1
此代碼將目標頁腳設置爲源頁腳,但在文檔的頁腳末尾添加了換行符。我如何刪除換行符?複製Word中的末尾沒有換行符的末尾
//quell Footer
Range sourceRngHFooter = srcWordDocument.Sections[1].Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
//target footer
Range targetRngFooter = newWordDocument.Sections[1].Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
讀取源頁腳並將其插入到目標頁腳
//sets the target footer to source footer
targetRngFooter.FormattedText = sourceRngHFooter.FormattedText;
複製粘貼變異看起來是這樣,但有同樣的問題:
sourceRngHeader.Copy();
targetRngHeader.Paste();
我嘗試了很多.. ,這將刪除換行符,但只有沒有格式的文本纔會被拷貝。
targetRngFooter.Text = sourceRngHFooter.Text.Remove(sourceRngHFooter.Text.LastIndexOf("\r"));
targetRngFooter.Font = sourceRngHFooter.Font;
targetRngFooter.Font.Color = sourceRngHFooter.FormattedText.Font.Color;
希望有人能幫助我!由於
更新:
但
爲什麼使用複製粘貼而不是從源文本讀取文本並將其保存在目標文件中?而當你真的想要使用FormattedText時,你爲什麼試圖從*文本中刪除EOL? –
這是一個嘗試,因爲我無法更改FormattedText的文本,我認爲我可以設置文本的格式。希望你能理解我的意思。 –