gpt4 book ai didi

c# - 如何在Word中的表格单元格中插入换行符?

转载 作者:太空宇宙 更新时间:2023-11-03 22:22:05 25 4
gpt4 key购买 nike

当我使用 C# 将 '\r\n' 插入到 word 文档中表格的单元格中时,它不起作用,为什么?怎么做?

Word.Application wordApp; 
Word.Document wordDoc;
filePath = @"" + strWorkPath + @"Uploads\Template\template.doc";
saveFilePath = @"" + strWorkPath + @"Uploads\" + VersionStr + @"\" + fileName;
object format = Word.WdSaveFormat.wdFormatDocument; wordApp = new Word.Application();
Object nothing = Missing.Value;
wordDoc = wordApp.Documents.Open(ref filePath, ref nothing, ref nothing, ref nothing, ref nothing,ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing);
Word.Table table = wordDoc.Tables[1];
table.Cell(1, 1).Range.Text = "sdsdlkfjdslk \r\n slkdfjslj";

如最后一行所示。

文档中是"sdsdlkfjdslk\r\n slkdfjslj",不是"sdsdlkfjdslk slkdfjslj"

最佳答案

尝试

"sdsdlkfjdslk" + (char)11 + "slkdfjslj" 

"sdsdlkfjdslk \v slkdfjslj"

关于c# - 如何在Word中的表格单元格中插入换行符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2742686/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com