# JDWorkPrepare.Net **Repository Path**: wyw_haha/JDWorkPrepare.Net ## Basic Information - **Project Name**: JDWorkPrepare.Net - **Description**: 学习使用C#+DocX库+NPIO库实现Excel读取及WORD文档生成。使用这种方法可以避免使用MS OFFICE库,从而可以在没有安装MS OFFICE的计算机上使用。 - **Primary Language**: C# - **License**: EPL-1.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 2 - **Created**: 2020-04-14 - **Last Updated**: 2022-09-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # JDWorkPrepare.Net #### 介绍 学习使用C#+DocX库+NPIO库实现Excel读取及WORD文档生成。使用这种方法可以避免使用MS OFFICE库,从而可以在没有安装MS OFFICE的计算机上使用。 其中探索了兼容wps的方法。使用docX生成的文件,在MS Office下打开时表格正常,但是在WPS中却宽度错误,因此尝试修改了DocX洪的源代码(搜索2310可找到修改点),固化了表格宽度,使得WPS和OFFICE的表格宽度分别控制。但具体原理并未研究。 #### 软件架构 .Net Framework 4.5.2 #### 使用说明 参见Bin/debug文件夹中的《使用说明》,使用导入文档范例EXCEL可生成Word #### 代码示例 #region 四、插入航材清单表格 table5 document.InsertParagraph("四、特殊航材清单").Font("微软雅黑").FontSize(13d).SpacingAfter(6d).SpacingBefore(24d).Bold().Alignment = Alignment.left; var columnWidths5 = new float[] { 6f, 32f, 32f, 30f }; var table5 = document.InsertTable(1, columnWidths5.Length); // Set the table's column width and background table5.SetWidthsPercentage(columnWidths4, 300f); table5.Design = TableDesign.TableGrid; table5.Alignment = Alignment.center; table5.AutoFit = AutoFit.Fixed;//ColumnWidth; var table5row1 = table5.Rows.First(); //填标题 table5row1.Cells[0].Paragraphs.First().Append("序号"); table5row1.Cells[1].Paragraphs.First().Append("航材名称"); table5row1.Cells[2].Paragraphs.First().Append("件号"); table5row1.Cells[3].Paragraphs.First().Append("序号备注"); int table5RowCount = 0;//用来标注该表格序号 for (int k = 0; k < ListDT.Rows.Count; k++) { int JobInfoDTRow = WriteDoc.Program.SearchJobcard(ListDT.Rows[k][CardNumCount].ToString(), ListDT.Rows[k][CardNameCount].ToString(), k);//找工卡名对应的数据库行数 if (JobInfoDTRow != 0) { if (Encoding.Default.GetByteCount(Job.Rows[JobInfoDTRow][12].ToString()) > 1)//找到对应工卡数据行,且该行的“特殊航材名称”列有内容,则填充 { var newtable5Row = table5.InsertRow(); newtable5Row.Cells[0].Paragraphs[0].Append((table5RowCount+1).ToString());//填序号 table5RowCount++; newtable5Row.Cells[1].Paragraphs[0].Append(Job.Rows[JobInfoDTRow][12].ToString());//填名称 newtable5Row.Cells[2].Paragraphs[0].Append(Job.Rows[JobInfoDTRow][13].ToString());//填件号 newtable5Row.Cells[3].Paragraphs[0].Append(Job.Rows[JobInfoDTRow][14].ToString());//填序号备注 } } } if (table5RowCount == 0)//如果一个特殊航材都没有,插入一行空行 { var newtable5Row = table5.InsertRow(); for (int i = 0; i < table5.ColumnCount; i++) newtable5Row.Cells[i].Paragraphs[0].Append("-");//填横线 } // 设置表格的最终格式--------------- //newCell.MarginLeft = 0; for (int i = 0; i < table5.RowCount; i++)//设置表格字体及字号 { for (int j = 0; j < table5.ColumnCount; j++) { table5.Rows[i].Cells[j].Paragraphs[0].Font("微软雅黑"); table5.Rows[i].Cells[j].Paragraphs[0].FontSize(9d); table5.Rows[i].Cells[j].Paragraphs[0].Alignment = Alignment.center; } } for (int i = 0; i < table5.ColumnCount; i++) table5.Rows[0].Cells[i].FillColor = Color.LightGray; table5.Alignment = Alignment.center; document.InsertParagraph(" ").FontSize(9d).SpacingAfter(9d); //document.InsertSectionPageBreak();//插入分页符 #endregion #### 码云特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md 2. 码云官方博客 [blog.gitee.com](https://blog.gitee.com) 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解码云上的优秀开源项目 4. [GVP](https://gitee.com/gvp) 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目 5. 码云官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) 6. 码云封面人物是一档用来展示码云会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)