亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

c# OpenXML WordprocessingDocumentType 在 TableCell

c# OpenXML WordprocessingDocumentType 在 TableCell

米脂 2023-08-21 17:55:27
是否可以將 HTML 片段插入到使用 OpenXML 創建的 WordProcessingDocument 的 TableCell 中?例如,當我使用:public void WriteWordFile(){    var fileName = HttpContext.Current.Request.PhysicalApplicationPath + "/temp/" + HttpContext.Current.Session.SessionID + ".docx";    using (var wordDocument = WordprocessingDocument.Create(fileName, WordprocessingDocumentType.Document, true))    {        var mainPart = wordDocument.AddMainDocumentPart();        mainPart.Document = new Document();        var body = mainPart.Document.AppendChild(new Body());        var table = new Table();        var tr = new TableRow();        var tc = new TableCell();        tc.Append(new Paragraph(new Run(new Text("1"))));        tr.Append(tc);        table.Append(tr);        body.Append(table);    }Word 文檔打印一個簡單的“1”,沒有預期的格式。然而,我想做的是寫:public void WriteWordFile(){    var fileName = HttpContext.Current.Request.PhysicalApplicationPath + "/temp/" + HttpContext.Current.Session.SessionID + ".docx";    using (var wordDocument = WordprocessingDocument.Create(fileName, WordprocessingDocumentType.Document, true))    {        var mainPart = wordDocument.AddMainDocumentPart();        mainPart.Document = new Document();        var body = mainPart.Document.AppendChild(new Body());        var table = new Table();        var tr = new TableRow();        var tc = new TableCell();        tc.Append(new Paragraph(new Run(new Text("<span style=\"bold\">1</span>"))));        tr.Append(tc);        table.Append(tr);        body.Append(table);    }}Word 文檔打印 HTML 標記“ <span style="bold">1</span>”而不是粗體“ 1 ”。
查看完整描述

1 回答

?
瀟瀟雨雨

TA貢獻1833條經驗 獲得超4個贊

不,Word 不支持問題中所描述的內容。

HTML 不是 Word 的本機格式 -需要轉換器才能將 HTML 合并到 Word 內容中。

在 UI 中,這是通過從文件粘貼或插入來完成的。

在 Open XML 中,可以使用該altChunk方法將外部格式的內容“嵌入”到文檔包中。當 Word 打開文檔并遇到一個文件時,altChunk它會調用適當的轉換器將其轉換為本機 Word 內容 (Word Open XML);在此過程中,原始嵌入內容將被刪除。但是,不能保證結果就是本機環境(在瀏覽器的 HTML 情況下)返回的結果。

搜索“altChunk”應該會出現大量討論、博客文章等。


查看完整回答
反對 回復 2023-08-21
  • 1 回答
  • 0 關注
  • 146 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號