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

Wed Oct 05, 2022 6:52 am

Image

如何設置Column間距的欄位間距

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

Wed Oct 05, 2022 7:28 am

您好,

您附加的图片在我这边显示失败,根据您的问题描述,我猜测您是想要设置表格的列宽对吗?如果是的话,请参考下面的代码。
Code: Select all
Document document = new Document();
            document.LoadFromFile(@"..\..\..\..\..\..\Data\TableSample.docx");

            Section section = document.Sections[0];
            Table table = section.Tables[0] as Table;

            //Traverse the first column
            for (int i = 0; i < table.Rows.Count; i++)
            {
                table.Rows[i].Cells[0].SetCellWidth(200,CellWidthType.Point);
            }

            //Save to file
            document.SaveToFile(@"ColumnWidth.docx", FileFormat.Docx);


Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3051
Joined: Wed Jun 27, 2012 8:50 am

Wed Oct 05, 2022 7:42 am

Code: Select all
https://firebasestorage.googleapis.com/v0/b/question-bank-dev.appspot.com/o/test%2F988.png?alt=media&token=6ac51657-a6e8-4d54-b40c-f9aba4553662

我直接給你圖片下載連結
主要是要設置分隔欄的間距

在Choose Page Layout > Columns. At the bottom of the list, choose More Columns.
改間距

Image

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

Wed Oct 05, 2022 9:52 am

您好,

感谢您提供进一步的信息。请通过 section.Columns.Populate(2, 20f);方法的第二个参数设置分栏间距。
下面是完整示例代码。
Code: Select all
   Document document = new Document();
            Section section = document.AddSection();
            section.AddParagraph().AppendText("test test test test test test test test test test test test test");

            //split the section into two columns with the space 20f
            section.Columns.Populate(2, 20f);
         
            section.PageSetup.ColumnsLineBetween = true;

            document.SaveToFile("result.docx", FileFormat.Docx2013);


Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3051
Joined: Wed Jun 27, 2012 8:50 am

Sat Oct 08, 2022 10:02 am

您好,

请问上面的方案可以满足您的需求吗?
期待您的反馈!

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3051
Joined: Wed Jun 27, 2012 8:50 am

Return to 中文技术支持

cron