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

Thu Mar 23, 2023 3:52 am

下面為代碼範例
Code: Select all
  Document document = new Document(@"C:\test6\轉檔.doc");
            var resultDoc = new Document();
            var newSection = resultDoc.AddSection();

            //只抓section0- table0 - row0- cell0 中的所有內容
            var section = document.Sections[0];
            var table = section.Tables[0];
            var row = table.Rows[0];
            var cell = row.Cells[0];

            var documentObjects = cell.ChildObjects; //以paragraph去切分,which is splited by 換行符號
            foreach (var documentObj in documentObjects)
            {
                var paragraph = documentObj as Paragraph;
                if (paragraph == null) continue;
                //clone
                newSection.Paragraphs.Add(paragraph.Clone() as Paragraph);
            }

            resultDoc.SaveToFile(@"C:\test6\轉檔後,「答案」兩個字的字型變小了.docx", FileFormat.Docx);



附檔 已寄到:support@e-iceblue.com
轉檔.doc copy 到 轉檔後,「答案」兩個字的字型變小了 .docx 答案字體變小了

yaowen2022
 
Posts: 17
Joined: Mon Mar 06, 2023 8:52 am

Thu Mar 23, 2023 10:16 am

您好,

感謝諮詢。
關於字體變小的問題,我調整了代碼,您可以參考下面的代碼再次測試。若還有其他問題,歡迎隨時聯繫我們。
Code: Select all
 
            Document document = new Document(@"Q2\轉檔.doc");
            var resultDoc = new Document();
            resultDoc.KeepSameFormat = true;
            var newSection = resultDoc.AddSection();

            //只抓section0- table0 - row0- cell0 中的所有內容
            var section = document.Sections[0];
            var table = section.Tables[0];
            var row = table.Rows[0];
            var cell = row.Cells[0];

            var documentObjects = cell.ChildObjects; //以paragraph去切分,which is splited by 換行符號
            foreach (var documentObj in documentObjects)
            {
                var paragraph = documentObj as Paragraph;
                if (paragraph == null) continue;             
                //clone
                int i = newSection.Paragraphs.Add(paragraph.Clone() as Paragraph);
                newSection.Paragraphs[i].GetStyle().CharacterFormat.FontSize =
                    paragraph.GetStyle().CharacterFormat.FontSize;
            }
            resultDoc.SaveToFile(@"Q2\Q2_output2.docx", FileFormat.Docx);


Sincerely,
Doris
E-iceblue support team
User avatar

Doris.Liu
 
Posts: 377
Joined: Mon Nov 07, 2022 8:10 am

Fri Mar 24, 2023 2:09 am

感謝回覆!!@

yaowen2022
 
Posts: 17
Joined: Mon Mar 06, 2023 8:52 am

Return to 中文技术支持