惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
博客园 - 三生石上(FineUI控件)
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
Microsoft Azure Blog
Microsoft Azure Blog
GbyAI
GbyAI
腾讯CDC
酷 壳 – CoolShell
酷 壳 – CoolShell
M
MIT News - Artificial intelligence
Stack Overflow Blog
Stack Overflow Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Jina AI
Jina AI
爱范儿
爱范儿
博客园 - 【当耐特】
雷峰网
雷峰网
S
SegmentFault 最新的问题
美团技术团队
Blog — PlanetScale
Blog — PlanetScale
The GitHub Blog
The GitHub Blog
有赞技术团队
有赞技术团队
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
Google DeepMind News
Google DeepMind News
J
Java Code Geeks

博客园 - soulsjie

一种在winfrom窗体中显示计算公式的解决方案 winform窗体DataGridView合并单元格处理 C#GDI+阴影笔刷样式HatchStyle探讨 C#代码混淆工具ConfuserEx的使用 Aspose.Words在指定位置插入图片、调整图片大小 C#获取对象实体的键值对信息 C#将Winform上的TextBox和ComBox的值导入和导出 C# Aspose.Words将word中自定义的标签进行替换 Python文件操作基础方法 C# 将项目资源文件保存到磁盘上 SqlSugar数据库辅助类 使用存储过程备份MS SQLServer数据库 案例3:JAVA GUI 随机点名程序 案例2:JAVA GUI 简易计算器 ArcGIS JS API 添加要素图层 点击时获取图层属性 ArcGIS JS API 将天地图设置为底图 HTML5PLUS实现类似右侧弹出菜单 SqlSugar各数据库连接串 案例1:JAVAGUI用户管理
C#使用Aspose.Words将Spread表格插入到Word中
soulsjie · 2023-02-23 · via 博客园 - soulsjie

注:Word中每个表格只有一行,固定第一行为表头,先复制表头N行追加到表格后,保证每行的格式与表头一致。
封装方法:

        private void SheetToTable(FarPoint.Win.Spread.SheetView sheet, Document doc, Table table, int beginRow)
        {
            //先复制出所有行,保证每行的格式都是一致的
            for (int i = beginRow; i < sheet.RowCount; i++)
            {
                Row oneRow = (Row)table.Rows[table.Rows.Count - 1].Clone(true);
                table.Rows.Insert(table.Rows.Count, oneRow);
            }
            //从第二行开始进行数据填充
            for (int i = beginRow; i < table.Rows.Count; i++)
            {
                //先统一设置一下行高,后续给单元格赋值时会自动撑开
                table.Rows[i].RowFormat.Height = 20;
                for (int j = 0; j < sheet.ColumnCount; j++)
                {
                    table.Rows[i].Cells[j].ChildNodes.Clear();
                    Paragraph p = new Paragraph(doc);
                    p.AppendChild(new Run(doc, sheet.Cells[i, j].Text));
                    table.Rows[i].Cells[j].AppendChild(p);
                }
            }
        }
        /// <summary>
        /// 设置指定单元格的文本
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="cell"></param>
        /// <param name="text"></param>
        public static void SetCellText(Document doc,Cell cell,string text) 
        {
            cell.RemoveAllChildren();
            cell.Paragraphs.Add(new Paragraph(doc));
            Run run = new Run(doc, text);
            run.Font.Name = "宋体";
            run.Font.Size = 8;
            cell.LastParagraph.Runs.Add(run);
        }