簡體   English   中英

我無法將從PowerPoint中提取的文本分成多行

[英]I can't Split the text extracted from powerpoint into multiple lines

我在文本的形狀中提取了一些文本,然后逐行將其打印到輸出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

有時,除了"\\n"之外,還將"\\r"用作新行。 如果文本顯示在帶有換行符的notepad ++中,則肯定存在notepad ++正在拾取的內容。 您可以通過單擊查看>顯示符號>顯示所有字符來查看每個字符的字符值。 當您在notepad ++中以這種方式查看它時,請找到每行末尾的內容,並根據C#代碼中的該字符進行拆分。

拆分\\r\\n

我喜歡這樣:

string[] lines = textRange.Text.ToString().Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM