我无法将从PowerPoint中提取的文本分成多行

时间:2019-06-11 20:28:40

标签: c# powerpoint

我在文本的形状内提取了一些文本,然后逐行将其打印到输出txt文件中,以便在实际执行我需要做的事情之前进行查看。

我遇到的问题是,用记事本++打开时我提取的文本可以看到有分成多行的文本,而在常规记事本中,这是一大块文本。有什么办法可以让我检测到下一行来拆分字符串吗?

这是我的代码

int linecounter = 1;
bool isDetailPage = false;
Application pptApplication = new Application();
Presentation pptPresentation = pptApplication.Presentations.Open(file, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
foreach (Slide _slide in pptPresentation.Slides) {
  tempOutput.Add("- Parsing Slide " + linecounter);
  foreach (Microsoft.Office.Interop.PowerPoint.Shape _shape in _slide.Shapes) {
    if(_shape.HasTextFrame == MsoTriState.msoTrue) {
      var textFrame = _shape.TextFrame;
      if(textFrame.HasText == MsoTriState.msoTrue) {
        var textRange = textFrame.TextRange;
        Match match = knowldgeSlide.Match(textRange.Text.ToString());
        if (match.Success) {
          isDetailPage = true;
        }
        if(isDetailPage) { //ignore other slides
          string[] lines = textRange.Text.ToString().Split(
            new[] { "\n" },
            StringSplitOptions.None
          );
          int t = 0;
          foreach(string x in lines) {
            tempOutput.Add("line " + t + ": " + x);
            t++;
          }
        }
      }
    }
  }
  isDetailPage = false;
  linecounter++;
}

这是从PowerPoint中提取的文本,我想将其拆分为5行字符串。

line 0: Identify the four benefits you gain from convergence and OTN? (Source: Identify the need for the NCS 4000 Series in the OTN Environment) 
Virtualized network operations
The scalability 
Reduction in transport costs
Flexibility allows operators to employ the technologies
Service contracts

2 个答案:

答案 0 :(得分:1)

有时"\r"除了"\n"之外还用作新行。如果文本显示在带有换行符的notepad ++中,则肯定存在notepad ++正在拾取的内容。您可以通过单击查看>显示符号>显示所有字符来查看每个字符的字符值。当您在notepad ++中以这种方式查看它时,请找到每行末尾的内容,并根据C#代码中的该字符进行拆分。

答案 1 :(得分:1)

def pruefeZeitbudget(eingabeZeitaufwand) @validierungsWert = eingabeZeitaufwand.to_f loop do if @validierungsWert > 24 puts 'Wert überschreitet das Tagesmaximum von 24 Stunden. Erneute Eingabe!' @validierungsWert = gets.chomp.to_f else puts 'Eingabe okay.' break end end \r上均分开。

我喜欢这样:

\n