为有中文需求的客户提供多渠道中文技术支持.

Tue Oct 11, 2022 6:11 am

範例如下
Code: Select all
            Document document = new Document();
            document.ViewSetup.DocumentViewType = DocumentViewType.NormalLayout;
            Section section = document.AddSection();
            Paragraph para = section.AddParagraph();
            para.AppendText("Test  哈哈哈");
            string fieldCode = @"\o(\s\do 0(1))";
            Field fieldRes = new Field(document);
            fieldRes.Code = fieldCode;
            fieldRes.Type = FieldType.FieldFormula;
            para.ChildObjects.Insert(0, fieldRes);
            FieldMark fm = new FieldMark(document, FieldMarkType.FieldEnd);
            para.ChildObjects.Insert(1, fm);
            document.SaveToFile(@"C:\doc\test.doc", Spire.Doc.FileFormat.Doc);
            document.Close();


使用 Spire.Doc 9.7.14 版本
成功顯示 1Test 哈哈哈
使用 Spire.Doc 10.9.6 版本
則只顯示 Test 哈哈哈

chihomis
 
Posts: 26
Joined: Fri Dec 18, 2020 1:10 am

Tue Oct 11, 2022 8:45 am

您好,

感謝您的留言。
在使用最新的Spire.Doc10.9.6中,妳需要更改FieldType類型使用 “FieldType.FieldEquation”來實現妳的需求。我把完整代碼放在下面供您參考。
如果您還有任何問題,歡迎隨時聯系。

Code: Select all
Document document = new Document();
            document.ViewSetup.DocumentViewType = DocumentViewType.NormalLayout;
            Section section = document.AddSection();

            Paragraph para = section.AddParagraph();
            para.AppendText("Test  哈哈哈");

            string fieldCode = @" \o(\s\do 0(1))";
            Field fieldRes = new Field(document);
            fieldRes.Code = fieldCode;
           fieldRes.Type = FieldType.FieldEquation;         
            para.ChildObjects.Insert(0, fieldRes);

            FieldMark fm = new FieldMark(document, FieldMarkType.FieldEnd);
            para.ChildObjects.Insert(1, fm);

            document.SaveToFile(@"../../output/test_10.9.6.doc", Spire.Doc.FileFormat.Doc);
            document.Close();


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Tue Oct 18, 2022 7:29 am

您好,

請問我提供的解決方案解決了您的問題了嗎?期待在您空閑的時候給出反饋。提前感謝。希望您有美好的壹天。

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Return to 中文技术支持