Dzwebs.Net

撰写电脑技术杂文十余年

aspose.words插入表格的代码

Admin | 2015-8-27 10:22:49 | 被阅次数 | 5633

温馨提示!

如果未能解决您的问题,请点击搜索;登陆可复制文章,点击登陆
public bool InsertTable(System.Data.DataTable dt, bool haveBorder) 
        { 
            Aspose.Words.Tables.Table  table= oWordApplic.StartTable();//开始画Table 
            ParagraphAlignment paragraphAlignmentValue = oWordApplic.ParagraphFormat.Alignment; 
            oWordApplic.ParagraphFormat.Alignment = ParagraphAlignment.Center; 
            //添加Word表格 
            for (int row = 0; row < dt.Rows.Count; row++) 
            { 
                 oWordApplic.RowFormat.Height =25; 
                for (int col = 0; col < dt.Columns.Count; col++) 
                { 
                    oWordApplic.InsertCell(); 
                    oWordApplic.Font.Size = 10.5; 
                    oWordApplic.Font.Name = "宋体"; 
                    oWordApplic.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;//垂直居中对齐 
                    oWordApplic.ParagraphFormat.Alignment = ParagraphAlignment.Center;//水平居中对齐 
                    oWordApplic.CellFormat.Width = 50.0; 
                    oWordApplic.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPoints(50); 
                    if (haveBorder == true) 
                    { 
                        //设置外框样式    
                        oWordApplic.CellFormat.Borders.LineStyle = LineStyle.Single; 
                        //样式设置结束    
                    } 
 
                    oWordApplic.Write(dt.Rows[row][col].ToString()); 
                } 
 
                oWordApplic.EndRow(); 
 
            } 
            oWordApplic.EndTable(); 
            oWordApplic.ParagraphFormat.Alignment = paragraphAlignmentValue; 
            table.Alignment=Aspose.Words.Tables.TableAlignment.Center; 
            table.PreferredWidth = Aspose.Words.Tables.PreferredWidth.Auto;  
            return true; 
        }

该杂文来自: 网站开发杂文

上一篇:aspose.words设置纸型的代码下篇

下一篇:aspose.words合并单元格的代码

网站备案号:

网站备案号:滇ICP备11001339号-7

版权属性:

Copyright 2007-2021-forever Inc. all Rights Reserved.

联系方式:

Email:dzwebs@126.com QQ:83539231 访问统计