Npoi导出非模板

最近使用NPOI做了个导出Word文档的功能,因为之前都是导出Excel很方便(不用模板),所以导出Word也选用了Npoi(也没有用模板,),开始之前没有查阅资料,非模板简直费劲的狠,有的方法查阅资料搜索出来的都不沾边,后来通过查阅资料与自己研究,终于把需求实现了,话不多说上代码,希望以后能够帮助到有需要的人

一 、首先引入NPOI NuGet:

版本说明

    NPOI 2.5.1 

       本次用到了最新版本的Npoi跟以前旧版本对比 有的方法没有找到

      通过Nuget搜索Npoi下载安装就好

  

二、创建页眉页脚(显示第几页共几页):

使用方式,如下所示:

如果我们没有特殊要求使用 只显示页眉页脚

   CT_Ftr m_ftr = new CT_Ftr();
      m_ftr.AddNewP().AddNewR().AddNewT().Value = "我是页脚";
XWPFRelation Frelation = XWPFRelation.FOOTER;
XWPFFooter m_f = (XWPFFooter)document.CreateRelationship(Frelation, XWPFFactory.GetInstance(), document.FooterList.Count + 1); //设置页脚
m_f.SetHeaderFooter(m_ftr);
m_f.SetXWPFDocument(document);
CT_HdrFtrRef m_HdrFtr1 = m_SectPr.AddNewFooterReference();
m_HdrFtr1.type = ST_HdrFtr.@default;
m_HdrFtr1.id = m_f.GetPackageRelationship().Id;

这里我需要显示第几页共几页 还会显示页脚有背景色 页眉有字体颜色等,如下:

  /// <summary>
/// 创建页眉
/// </summary>
/// <param name="document"></param>
/// <param name="m_SectPr"></param>
/// <param name="jo"></param>
public static void CreateHeader(XWPFDocument document, CT_SectPr m_SectPr, QuotationExportEntity.QuotationDetailInfoRequest Entity)
{ int FontSize = 17;
//创建页眉
CT_Hdr m_Hdr = new CT_Hdr();
m_Hdr.Items = new System.Collections.ArrayList();//添加多个头信息
CT_SdtBlock m_Sdt = new CT_SdtBlock();
CT_SdtContentBlock m_SdtContent = m_Sdt.AddNewSdtContent();
CT_P m_SdtContentP = m_SdtContent.AddNewP();
CT_PPr m_SdtContentPpPr = m_SdtContentP.AddNewPPr();
m_SdtContentPpPr.AddNewJc().val = ST_Jc.left;
m_SdtContentP.Items = new System.Collections.ArrayList();
CT_R m_SdtR = m_SdtContentP.AddNewR();
CT_RPr m_ctrpr = m_SdtR.AddNewRPr();
CT_Fonts rfonts = m_ctrpr.AddNewRFonts(); //添加新的字体
CT_Color rColor = m_ctrpr.AddNewColor(); //改变页字体颜色
rColor.val = "red";
rfonts.ascii = "新微软雅黑";
rfonts.eastAsia = "新微软雅黑";
m_ctrpr.AddNewSz().val = (ulong)FontSize; m_SdtR.AddNewT().Value = "联想报价单 ";
m_SdtR = m_SdtContentP.AddNewR();
m_ctrpr = m_SdtR.AddNewRPr();
m_ctrpr.AddNewSz().val = (ulong)FontSize;
m_SdtR.AddNewT().Value = "" + Entity.quotationNumber.ToString() + "-买方名称:" + Entity.customerName + " ";
m_SdtR = m_SdtContentP.AddNewR();
m_ctrpr = m_SdtR.AddNewRPr();
rColor = m_ctrpr.AddNewColor();
rColor.val = "red";
if (!string.IsNullOrEmpty(Entity.lenovoLinkName) && string.IsNullOrEmpty(Entity.customerPhone))
{
m_ctrpr.AddNewSz().val = (ulong)FontSize;
m_SdtR.AddNewT().Value = " 客户经理:";
m_SdtR = m_SdtContentP.AddNewR();
m_ctrpr = m_SdtR.AddNewRPr();
m_ctrpr.AddNewSz().val = (ulong)FontSize;
m_SdtR.AddNewT().Value = "" + Entity.lenovoLinkName + " (" + Entity.customerPhone + ") ";
}
m_Hdr.Items.Add(m_Sdt);
XWPFRelation Hrelation = XWPFRelation.HEADER;
XWPFHeader m_h = (XWPFHeader)document.CreateRelationship(Hrelation, XWPFFactory.GetInstance());
//设置页眉
m_h.SetHeaderFooter(m_Hdr);
CT_HdrFtrRef m_HdrFtr2 = m_SectPr.AddNewHeaderReference();
m_HdrFtr2.type = ST_HdrFtr.@default;
m_HdrFtr2.id = m_h.GetPackageRelationship().Id; }
/// <summary>
/// 创建页脚
/// </summary>
/// <param name="document"></param>
/// <param name="m_SectPr"></param>
/// <param name="jo"></param>
public static void CreateFooter(XWPFDocument document, CT_SectPr m_SectPr, QuotationExportEntity.QuotationDetailInfoRequest Entity)
{
int FontSize = 17;
CT_Ftr m_ftr = new CT_Ftr();
m_ftr.Items = new System.Collections.ArrayList();
CT_SdtBlock m_Sdt = new CT_SdtBlock();
CT_SdtPr m_SdtPr = m_Sdt.AddNewSdtPr();
CT_SdtDocPart m_SdtDocPartObj = m_SdtPr.AddNewDocPartObj();
m_SdtDocPartObj.AddNewDocPartGallery().val = "Page Numbers (Bottom of Page)";
m_SdtDocPartObj.docPartUnique = new CT_OnOff();
m_Sdt.AddNewSdtEndPr();
CT_SdtContentBlock m_SdtContent = m_Sdt.AddNewSdtContent();
CT_P m_SdtContentP = m_SdtContent.AddNewP();
CT_PPr m_SdtContentPpPr = m_SdtContentP.AddNewPPr();
m_SdtContentPpPr.AddNewJc().val = ST_Jc.left;
m_SdtContentP.Items = new System.Collections.ArrayList();
CT_SimpleField m_fldSimple = new CT_SimpleField();
CT_R m_SdtR = m_SdtContentP.AddNewR();
CT_RPr m_ctrpr = m_SdtR.AddNewRPr();
CT_Fonts rfonts = m_ctrpr.AddNewRFonts(); //添加新的字体
CT_Color rColor = m_ctrpr.AddNewColor(); //改变页字体颜色
CT_OnOff bBold = m_ctrpr.AddNewB(); //字体加粗
CT_OnOff bcsCold = m_ctrpr.AddNewBCs();
rColor.val = "white";
rfonts.ascii = "新微软雅黑";
rfonts.eastAsia = "新微软雅黑";
m_ctrpr.AddNewSz().val = (ulong)FontSize;
m_ctrpr.AddNewSzCs().val = (ulong)FontSize;
m_SdtR.AddNewRPr().AddNewLang().val = "zh-CN"; //代表的是语言文化代码和国家地区
CT_Highlight rHighlight = new CT_Highlight();
rHighlight.val = ST_HighlightColor.black;
m_ctrpr.highlight = rHighlight;
bBold.val = true;
bcsCold.val = true;
m_SdtR.AddNewT().Value = " 联想商用PC ";
m_ftr.Items.Add(m_Sdt); m_SdtR = m_SdtContentP.AddNewR();
m_ctrpr = m_SdtR.AddNewRPr();
rfonts = m_ctrpr.AddNewRFonts();
rfonts.ascii = "新微软雅黑";
rfonts.eastAsia = "新微软雅黑";
m_ctrpr.AddNewSz().val = (ulong)FontSize;
m_ctrpr.AddNewSzCs().val = (ulong)FontSize;
m_SdtR.AddNewRPr().AddNewLang().val = "zh-CN"; //代表的是语言文化代码和国家地区
m_SdtR.AddNewT().Value = " "; m_SdtR = m_SdtContentP.AddNewR();
m_ctrpr = m_SdtR.AddNewRPr();
rfonts = m_ctrpr.AddNewRFonts();
rfonts.ascii = "新微软雅黑";
rfonts.eastAsia = "新微软雅黑";
m_ctrpr.AddNewSz().val = (ulong)FontSize;
m_ctrpr.AddNewSzCs().val = (ulong)FontSize;
m_SdtR.AddNewRPr().AddNewLang().val = "zh-CN"; //代表的是语言文化代码和国家地区
rHighlight = new CT_Highlight();
rHighlight.val = ST_HighlightColor.red;
m_ctrpr.highlight = rHighlight;
bBold = m_ctrpr.AddNewB(); //字体加粗
bcsCold = m_ctrpr.AddNewBCs();
bBold.val = true;
bcsCold.val = true;
rColor = m_ctrpr.AddNewColor();
rColor.val = "white";
m_SdtR.AddNewT().Value = " 专业,只为更好 "; m_SdtR = m_SdtContentP.AddNewR();
m_ctrpr = m_SdtR.AddNewRPr();
rfonts = m_ctrpr.AddNewRFonts();
rfonts.ascii = "新微软雅黑";
rfonts.eastAsia = "新微软雅黑";
m_ctrpr.AddNewSz().val = (ulong)FontSize;
m_ctrpr.AddNewSzCs().val = (ulong)FontSize;
m_SdtR.AddNewRPr().AddNewLang().val = "zh-CN"; //代表的是语言文化代码和国家地区
m_SdtR.AddNewT().Value = " 第";
m_fldSimple.instr = " PAGE \\* Arabic \\* MERGEFORMAT ";
m_SdtContentP.Items.Add(m_fldSimple); m_SdtR = m_SdtContentP.AddNewR();
m_ctrpr = m_SdtR.AddNewRPr();
rfonts = m_ctrpr.AddNewRFonts();
rfonts.ascii = "新微软雅黑";
rfonts.eastAsia = "新微软雅黑";
m_ctrpr.AddNewSz().val = (ulong)FontSize;
m_ctrpr.AddNewSzCs().val = (ulong)FontSize;
m_ctrpr.AddNewLang().val = "zh-CN";
m_SdtR.AddNewT().Value = "页 共";// /
m_fldSimple = new CT_SimpleField();
m_fldSimple.instr = " NUMPAGES \\* Arabic \\* MERGEFORMAT ";
m_SdtContentP.Items.Add(m_fldSimple); m_SdtR = m_SdtContentP.AddNewR();
m_ctrpr = m_SdtR.AddNewRPr();
rfonts = m_ctrpr.AddNewRFonts();
rfonts.ascii = "新微软雅黑";
rfonts.eastAsia = "新微软雅黑";
m_ctrpr.AddNewSz().val = (ulong)FontSize;
m_ctrpr.AddNewSzCs().val = (ulong)FontSize;
m_ctrpr.AddNewLang().val = "zh-CN";
m_SdtR.AddNewT().Value = "页"; //创建页脚关系
//m_ftr.AddNewP().AddNewR().AddNewT().Value = "我是页脚";
XWPFRelation Frelation = XWPFRelation.FOOTER;
XWPFFooter m_f = (XWPFFooter)document.CreateRelationship(Frelation, XWPFFactory.GetInstance(), document.FooterList.Count + 1);
//设置页脚
m_f.SetHeaderFooter(m_ftr);
m_f.SetXWPFDocument(document);
CT_HdrFtrRef m_HdrFtr1 = m_SectPr.AddNewFooterReference();
m_HdrFtr1.type = ST_HdrFtr.@default;
m_HdrFtr1.id = m_f.GetPackageRelationship().Id;
}

三、创建段落 文本 表格 插入图片 垂直合并单元格:

合并单元格查阅资料很多都是边创建表格边合并,这里是创建完表格在合并

/// <summary>
/// 创建word文档中的段落对象和设置段落文本的基本样式(字体大小,字体,字体颜色,字体对齐位置)
/// </summary>
/// <param name="document">document文档对象</param>
/// <param name="fillContent">段落第一个文本对象填充的内容</param>
/// <param name="isBold">是否加粗</param>
/// <param name="fontSize">字体大小</param>
/// <param name="fontFamily">字体</param>
/// <param name="paragraphAlign">段落排列(左对齐,居中,右对齐)</param>
/// <param name="isStatement">是否在同一段落创建第二个文本对象(解决同一段落里面需要填充两个或者多个文本值的情况,多个文本需要自己拓展,现在最多支持两个)</param>
/// <param name="secondFillContent">第二次声明的文本对象填充的内容,样式与第一次的一致</param>
/// <returns></returns>
private static XWPFParagraph ParagraphInstanceSetting(XWPFDocument document, string fillContent, bool isBold, int fontSize, string fontFamily, string rgbStr, UnderlinePatterns value, ParagraphAlignment paragraphAlign, ParagraphAlignment secondParagraphAlign, int secondFontSize = 0, bool isStatement = false, string secondFillContent = "")
{
XWPFParagraph paragraph = document.CreateParagraph();//创建段落对象
paragraph.Alignment = paragraphAlign;//文字显示位置,段落排列(左对齐,居中,右对齐) XWPFRun xwpfRun = paragraph.CreateRun();//创建段落文本对象 xwpfRun.IsBold = isBold;//文字加粗
xwpfRun.SetText(fillContent);//填充内容
xwpfRun.FontSize = fontSize;//设置文字大小
xwpfRun.SetFontFamily(fontFamily, FontCharRange.None); //设置标题样式如:(微软雅黑,隶书,楷体)根据自己的需求而定
xwpfRun.SetColor(rgbStr);//设置字体颜色--十六进制
xwpfRun.SetUnderline(value);//设置下划线,枚举类型
xwpfRun.AddTab();
//第二个文本的样式
if (isStatement)
{
XWPFRun secondxwpfRun = paragraph.CreateRun();//创建段落文本对象
secondxwpfRun.IsBold = isBold;//文字加粗
secondxwpfRun.SetText(secondFillContent);//填充内容
secondxwpfRun.FontSize = secondFontSize;//设置文字大小
secondxwpfRun.SetFontFamily(fontFamily, FontCharRange.None); //设置标题样式如:(微软雅黑,隶书,楷体)根据自己的需求而定
}
return paragraph;
} /// <summary>
/// 创建Word文档中表格段落实例和设置表格段落文本的基本样式(字体大小,字体,字体颜色,字体对齐位置)
/// </summary>
/// <param name="document">document文档对象</param>
/// <param name="table">表格对象</param>
/// <param name="fillContent">要填充的文字</param>
/// <param name="paragraphAlign">段落排列(左对齐,居中,右对齐)</param>
/// <param name="textPosition">设置文本位置(设置两行之间的行间,从而实现表格文字垂直居中的效果),从而实现table的高度设置效果 </param>
/// <param name="isBold">是否加粗(true加粗,false不加粗)</param>
/// <param name="fontSize">字体大小</param>
/// <param name="fontColor">字体颜色--十六进制</param>
/// <param name="isItalic">是否设置斜体(字体倾斜)</param>
/// <returns></returns>
public static XWPFParagraph SetTableParagraphInstanceSetting(XWPFDocument document, XWPFTable table, string fillContent, ParagraphAlignment paragraphAlign, int textPosition = 24, bool isBold = false, int fontSize = 10, string fontColor = "000000", bool isItalic = false, UnderlinePatterns value = UnderlinePatterns.None, int secondFontSize = 0, bool isStatement = false, string secondFillContent = "")
{
var para = new CT_P(); //设置单元格文本对齐
para.AddNewPPr().AddNewTextAlignment();
XWPFParagraph paragraph = new XWPFParagraph(para, table.Body);//创建表格中的段落对象
paragraph.Alignment = paragraphAlign; XWPFRun xwpfRun = paragraph.CreateRun();//
xwpfRun.SetText(fillContent);
xwpfRun.FontSize = fontSize;//字体大小
xwpfRun.SetColor(fontColor);//设置字体颜色--十六进制
xwpfRun.IsItalic = isItalic;//是否设置斜体(字体倾斜)
xwpfRun.IsBold = isBold;//是否加粗
xwpfRun.SetFontFamily("宋体", FontCharRange.None);//设置字体(如:微软雅黑,华文楷体,宋体)
xwpfRun.TextPosition = textPosition;//设置文本位置(设置两行之间的行间),从而实现table的高度设置效果
xwpfRun.SetUnderline(value);//设置下划线,枚举类型 //第二个文本的样式
if (isStatement)
{
XWPFRun secondxwpfRun = paragraph.CreateRun();//创建段落文本对象
secondxwpfRun.SetText(secondFillContent);
secondxwpfRun.FontSize = secondFontSize;//字体大小
secondxwpfRun.SetColor(fontColor);//设置字体颜色--十六进制
secondxwpfRun.IsItalic = isItalic;//是否设置斜体(字体倾斜)
secondxwpfRun.IsBold = isBold;//是否加粗
secondxwpfRun.SetFontFamily("宋体", FontCharRange.None);//设置字体(如:微软雅黑,华文楷体,宋体)
secondxwpfRun.TextPosition = textPosition;//设置文本位置(设置两行之间的行间),从而实现table的高度设置效果
secondxwpfRun.SetUnderline(value);//设置下划线,枚举类型
}
return paragraph;
} /// <summary>
/// Table中插入图片
/// </summary>
/// <param name="document">document文档对象</param>
/// <param name="table">表格对象</param>
/// <param name="path">路径</param>
private static XWPFParagraph SetWritePicture(XWPFDocument document, XWPFTable table, string path, ParagraphAlignment paragraphAlign, NPOI.XWPF.UserModel.PictureType type, int widthEmus, int heightEmus)
{
var para = new CT_P();
XWPFParagraph xwpfPicture = new XWPFParagraph(para, table.Body);//创建表格中的段落对象
xwpfPicture.Alignment = paragraphAlign;
XWPFRun runPicture = xwpfPicture.CreateRun(); using (FileStream picData = new FileStream(path, FileMode.Open, FileAccess.Read))
{
runPicture.AddPicture(picData, (int)type, "11.png", widthEmus, heightEmus);
}
//为了解决Npoi版本Bug
CT_Inline inline = runPicture.GetCTR().GetDrawingList()[0].inline[0];
inline.docPr.id = 1;
return xwpfPicture;
}
/// <summary>
/// 垂直合并单元格(先创建表格后合并)
/// </summary>
/// <param name="table"></param>
/// <param name="fromCol"></param>
/// <param name="toCol"></param>
/// <param name="fromRow"></param>
/// <param name="toRow"></param>
/// <returns></returns>
public static void MYMergeCells(XWPFTable table, int fromCol, int toCol, int fromRow, int toRow)
{
for (int rowIndex = fromRow; rowIndex <= toRow; rowIndex++)
{
if (fromCol < toCol)
{
table.GetRow(rowIndex).MergeCells(fromCol, toCol);
}
XWPFTableCell rowcell = table.GetRow(rowIndex).GetCell(fromCol);
CT_Tc cttc = rowcell.GetCTTc();
if (cttc.tcPr == null)
{
cttc.AddNewTcPr();
}
if (rowIndex == fromRow)
{
// The first merged cell is set with RESTART merge value
rowcell.GetCTTc().tcPr.AddNewVMerge().val = ST_Merge.restart;
}
else
{
// Cells which join (merge) the first one, are set with CONTINUE
rowcell.GetCTTc().tcPr.AddNewVMerge().val = ST_Merge.@continue;
}
}
}
/// <summary>
/// 创建word文档中的段落对象和设置段落文本的基本样式(字体大小,字体,字体颜色,字体对齐位置)
/// </summary>
/// <param name="document">document文档对象</param>
/// <param name="fillContent">段落第一个文本对象填充的内容</param>
/// <param name="isBold">是否加粗</param>
/// <param name="fontSize">字体大小</param>
/// <param name="fontFamily">字体</param>
/// <param name="paragraphAlign">段落排列(左对齐,居中,右对齐)</param>
/// <param name="isStatement">是否在同一段落创建第二个文本对象(解决同一段落里面需要填充两个或者多个文本值的情况,多个文本需要自己拓展,现在最多支持两个)</param>
/// <param name="secondFillContent">第二次声明的文本对象填充的内容,样式与第一次的一致</param>
/// <returns></returns>
private static XWPFParagraph ParagraphInstanceSetting(XWPFDocument document, string fillContent, bool isBold, int fontSize, string fontFamily, string rgbStr, UnderlinePatterns value, ParagraphAlignment paragraphAlign, ParagraphAlignment secondParagraphAlign, int secondFontSize = 0, bool isStatement = false, string secondFillContent = "")
{
XWPFParagraph paragraph = document.CreateParagraph();//创建段落对象
paragraph.Alignment = paragraphAlign;//文字显示位置,段落排列(左对齐,居中,右对齐) XWPFRun xwpfRun = paragraph.CreateRun();//创建段落文本对象 xwpfRun.IsBold = isBold;//文字加粗
xwpfRun.SetText(fillContent);//填充内容
xwpfRun.FontSize = fontSize;//设置文字大小
xwpfRun.SetFontFamily(fontFamily, FontCharRange.None); //设置标题样式如:(微软雅黑,隶书,楷体)根据自己的需求而定
xwpfRun.SetColor(rgbStr);//设置字体颜色--十六进制
xwpfRun.SetUnderline(value);//设置下划线,枚举类型
xwpfRun.AddTab();
//第二个文本的样式
if (isStatement)
{
XWPFRun secondxwpfRun = paragraph.CreateRun();//创建段落文本对象
secondxwpfRun.IsBold = isBold;//文字加粗
secondxwpfRun.SetText(secondFillContent);//填充内容
secondxwpfRun.FontSize = secondFontSize;//设置文字大小
secondxwpfRun.SetFontFamily(fontFamily, FontCharRange.None); //设置标题样式如:(微软雅黑,隶书,楷体)根据自己的需求而定
}
return paragraph;
} /// <summary>
/// 创建Word文档中表格段落实例和设置表格段落文本的基本样式(字体大小,字体,字体颜色,字体对齐位置)
/// </summary>
/// <param name="document">document文档对象</param>
/// <param name="table">表格对象</param>
/// <param name="fillContent">要填充的文字</param>
/// <param name="paragraphAlign">段落排列(左对齐,居中,右对齐)</param>
/// <param name="textPosition">设置文本位置(设置两行之间的行间,从而实现表格文字垂直居中的效果),从而实现table的高度设置效果 </param>
/// <param name="isBold">是否加粗(true加粗,false不加粗)</param>
/// <param name="fontSize">字体大小</param>
/// <param name="fontColor">字体颜色--十六进制</param>
/// <param name="isItalic">是否设置斜体(字体倾斜)</param>
/// <returns></returns>
public static XWPFParagraph SetTableParagraphInstanceSetting(XWPFDocument document, XWPFTable table, string fillContent, ParagraphAlignment paragraphAlign, int textPosition = 24, bool isBold = false, int fontSize = 10, string fontColor = "000000", bool isItalic = false, UnderlinePatterns value = UnderlinePatterns.None, int secondFontSize = 0, bool isStatement = false, string secondFillContent = "")
{
var para = new CT_P(); //设置单元格文本对齐
para.AddNewPPr().AddNewTextAlignment();
XWPFParagraph paragraph = new XWPFParagraph(para, table.Body);//创建表格中的段落对象
paragraph.Alignment = paragraphAlign; XWPFRun xwpfRun = paragraph.CreateRun();//
xwpfRun.SetText(fillContent);
xwpfRun.FontSize = fontSize;//字体大小
xwpfRun.SetColor(fontColor);//设置字体颜色--十六进制
xwpfRun.IsItalic = isItalic;//是否设置斜体(字体倾斜)
xwpfRun.IsBold = isBold;//是否加粗
xwpfRun.SetFontFamily("宋体", FontCharRange.None);//设置字体(如:微软雅黑,华文楷体,宋体)
xwpfRun.TextPosition = textPosition;//设置文本位置(设置两行之间的行间),从而实现table的高度设置效果
xwpfRun.SetUnderline(value);//设置下划线,枚举类型 //第二个文本的样式
if (isStatement)
{
XWPFRun secondxwpfRun = paragraph.CreateRun();//创建段落文本对象
secondxwpfRun.SetText(secondFillContent);
secondxwpfRun.FontSize = secondFontSize;//字体大小
secondxwpfRun.SetColor(fontColor);//设置字体颜色--十六进制
secondxwpfRun.IsItalic = isItalic;//是否设置斜体(字体倾斜)
secondxwpfRun.IsBold = isBold;//是否加粗
secondxwpfRun.SetFontFamily("宋体", FontCharRange.None);//设置字体(如:微软雅黑,华文楷体,宋体)
secondxwpfRun.TextPosition = textPosition;//设置文本位置(设置两行之间的行间),从而实现table的高度设置效果
secondxwpfRun.SetUnderline(value);//设置下划线,枚举类型
}
return paragraph;
} /// <summary>
/// Table中插入图片
/// </summary>
/// <param name="document">document文档对象</param>
/// <param name="table">表格对象</param>
/// <param name="path">路径</param>
private static XWPFParagraph SetWritePicture(XWPFDocument document, XWPFTable table, string path, ParagraphAlignment paragraphAlign, NPOI.XWPF.UserModel.PictureType type, int widthEmus, int heightEmus)
{
var para = new CT_P();
XWPFParagraph xwpfPicture = new XWPFParagraph(para, table.Body);//创建表格中的段落对象
xwpfPicture.Alignment = paragraphAlign;
XWPFRun runPicture = xwpfPicture.CreateRun(); using (FileStream picData = new FileStream(path, FileMode.Open, FileAccess.Read))
{
runPicture.AddPicture(picData, (int)type, "11.png", widthEmus, heightEmus);
}
//为了解决Npoi版本Bug
CT_Inline inline = runPicture.GetCTR().GetDrawingList()[0].inline[0];
inline.docPr.id = 1;
return xwpfPicture;
}
/// <summary>
/// 垂直合并单元格(先创建表格后合并)
/// </summary>
/// <param name="table"></param>
/// <param name="fromCol"></param>
/// <param name="toCol"></param>
/// <param name="fromRow"></param>
/// <param name="toRow"></param>
/// <returns></returns>
public static void MYMergeCells(XWPFTable table, int fromCol, int toCol, int fromRow, int toRow)
{
for (int rowIndex = fromRow; rowIndex <= toRow; rowIndex++)
{
if (fromCol < toCol)
{
table.GetRow(rowIndex).MergeCells(fromCol, toCol);
}
XWPFTableCell rowcell = table.GetRow(rowIndex).GetCell(fromCol);
CT_Tc cttc = rowcell.GetCTTc();
if (cttc.tcPr == null)
{
cttc.AddNewTcPr();
}
if (rowIndex == fromRow)
{
// The first merged cell is set with RESTART merge value
rowcell.GetCTTc().tcPr.AddNewVMerge().val = ST_Merge.restart;
}
else
{
// Cells which join (merge) the first one, are set with CONTINUE
rowcell.GetCTTc().tcPr.AddNewVMerge().val = ST_Merge.@continue;
}
}
}

四、 生成Word,控制表格允许跨页断行

PictureAddress fileJArray = GetEcaiFile(Entity);
string currentDate = DateTime.Now.ToString("yyyyMMdd");
//保存文件到静态资源wwwroot,使用绝对路径路径
var uploadPath = "Temp";
if (!Path.IsPathRooted(uploadPath))
{
uploadPath = HttpContext.Current.Server.MapPath("~") + "Temp";
}
string fileName = string.Format("{0}.docx", "联想商用产品报价单", System.Text.Encoding.UTF8);
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
}
int TableIndex = 0;
int DocIndex = 0;
int RowIndex = 5;
//通过使用文件流,创建文件流对象,向文件流中写入内容,并保存为Word文档格式
using (var stream = new FileStream(Path.Combine(uploadPath, fileName), FileMode.Create, FileAccess.Write))
{
//创建document文档对象对象实例
XWPFDocument document = new XWPFDocument();
document.Document.body.sectPr = new CT_SectPr();
CT_SectPr m_SectPr = document.Document.body.sectPr;
m_SectPr.pgSz.h = (ulong)16838;
m_SectPr.pgSz.w = (ulong)11906;
m_SectPr.pgMar.left = (ulong)1000;//左边距
m_SectPr.pgMar.right = (ulong)1000;//右边距
//创建页脚 带页码(第几页 共几页)
CreateFooter(document, m_SectPr, Entity);
//创建页眉
CreateHeader(document, m_SectPr, Entity);
////文本标题
document.SetParagraph(ParagraphInstanceSetting(document, "联想商用产品报价单", true, 15, "微软雅黑", "", UnderlinePatterns.None, ParagraphAlignment.CENTER, ParagraphAlignment.RIGHT), DocIndex++);
document.SetParagraph(ParagraphInstanceSetting(document, "", false, 14, "微软雅黑", "", UnderlinePatterns.None, ParagraphAlignment.RIGHT, ParagraphAlignment.RIGHT, 10, false, ""), DocIndex++);
#region Table0
XWPFTable zeroXwpfTable = document.CreateTable(2, 3);//显示的行列数rows:3行,cols:4列
CT_Tbl zeroTable = document.Document.body.GetTblArray()[TableIndex++];
zeroTable.AddNewTblPr().jc = new CT_Jc();
zeroTable.AddNewTblPr().jc.val = ST_Jc.center;//表在页面水平居中
zeroTable.AddNewTblPr().AddNewTblW().w = "9000";//表宽度
zeroTable.AddNewTblPr().AddNewTblW().type = ST_TblWidth.dxa;
CT_TcPr zeroPr = zeroXwpfTable.GetRow(0).GetCell(0).GetCTTc().AddNewTcPr();

zeroPr.tcW = new CT_TblWidth();
zeroPr.tcW.w = "3500";//单元格宽
zeroPr.tcW.type = ST_TblWidth.dxa;
zeroPr = zeroXwpfTable.GetRow(0).GetCell(1).GetCTTc().AddNewTcPr();
zeroPr.tcW = new CT_TblWidth();
zeroPr.tcW.w = "1000";//单元格宽
zeroPr.tcW.type = ST_TblWidth.dxa;
zeroPr = zeroXwpfTable.GetRow(0).GetCell(2).GetCTTc().AddNewTcPr();
zeroPr.tcW = new CT_TblWidth();
zeroPr.tcW.w = "4000";//单元格宽
zeroPr.tcW.type = ST_TblWidth.dxa;

zeroXwpfTable.SetBottomBorder(XWPFBorderType.NONE, 1, 0, null);
zeroXwpfTable.SetLeftBorder(XWPFBorderType.NONE, 1, 0, null);
zeroXwpfTable.SetTopBorder(XWPFBorderType.NONE, 1, 0, null);
zeroXwpfTable.SetRightBorder(XWPFBorderType.NONE, 1, 0, null);
zeroXwpfTable.SetInsideHBorder(XWPFBorderType.NONE, 1, 0, null);
zeroXwpfTable.SetInsideVBorder(XWPFBorderType.NONE, 1, 0, null);
MYMergeCells(zeroXwpfTable, 2, 2, 0, 1);
zeroXwpfTable.GetRow(0).GetCell(0).SetVerticalAlignment(XWPFVertAlign.CENTER);
zeroXwpfTable.GetRow(1).GetCell(0).SetVerticalAlignment(XWPFVertAlign.CENTER);
zeroXwpfTable.GetRow(1).GetCell(2).SetVerticalAlignment(XWPFVertAlign.CENTER);
zeroXwpfTable.GetRow(0).GetCell(0).SetColor("#E12826");
zeroXwpfTable.GetRow(1).GetCell(0).SetColor("#E12826");

zeroXwpfTable.GetRow(0).GetCell(0).SetParagraph(SetTableParagraphInstanceSetting(document, zeroXwpfTable, " 报价单编号", ParagraphAlignment.LEFT, 0, true, 10, "white", false, UnderlinePatterns.None, 10, true, Entity.quotationNumber.ToString()));
zeroXwpfTable.GetRow(0).GetCell(2).SetParagraph(SetWritePicture(document, zeroXwpfTable, HttpContext.Current.Server.MapPath("~") + "Images/2.png".ToString(), ParagraphAlignment.RIGHT, NPOI.XWPF.UserModel.PictureType.PNG, 160 * 9525, 38 * 9525));
zeroXwpfTable.GetRow(1).GetCell(0).SetParagraph(SetTableParagraphInstanceSetting(document, zeroXwpfTable, " 客户名称 ", ParagraphAlignment.LEFT, 10, true, 10, "white", false, UnderlinePatterns.None, 10, true, Entity.customerName.ToString()));
#endregion
document.SetParagraph(ParagraphInstanceSetting(document, "", false, 14, "微软雅黑", "", UnderlinePatterns.None, ParagraphAlignment.RIGHT, ParagraphAlignment.RIGHT, 10, false, ""), DocIndex++);
if (Entity.quoteExport == 1)
{
#region Table1
XWPFTable firstXwpfTable = document.CreateTable(4, 2);//显示的行列数rows:3行,cols:4列
CT_Tbl firstTable = document.Document.body.GetTblArray()[TableIndex++];
firstTable.AddNewTblPr().jc = new CT_Jc();
firstTable.AddNewTblPr().jc.val = ST_Jc.center;//表在页面水平居中
firstTable.AddNewTblPr().AddNewTblW().w = "9000";//表宽度
firstTable.AddNewTblPr().AddNewTblW().type = ST_TblWidth.dxa;
CT_TcPr firstPr = firstXwpfTable.GetRow(0).GetCell(0).GetCTTc().AddNewTcPr();
firstPr.tcW = new CT_TblWidth();
firstPr.tcW.w = "5000";//单元格宽
firstPr.tcW.type = ST_TblWidth.dxa;
firstPr = firstXwpfTable.GetRow(0).GetCell(1).GetCTTc().AddNewTcPr();
firstPr.tcW = new CT_TblWidth();
firstPr.tcW.w = "3000";//单元格宽
firstPr.tcW.type = ST_TblWidth.dxa;
firstXwpfTable.SetBottomBorder(XWPFBorderType.NONE, 1, 0, null);
firstXwpfTable.SetLeftBorder(XWPFBorderType.NONE, 1, 0, null);
firstXwpfTable.SetTopBorder(XWPFBorderType.NONE, 1, 0, null);
firstXwpfTable.SetRightBorder(XWPFBorderType.NONE, 1, 0, null);
firstXwpfTable.SetInsideHBorder(XWPFBorderType.NONE, 1, 0, null);
firstXwpfTable.SetInsideVBorder(XWPFBorderType.NONE, 1, 0, null);
firstXwpfTable.GetRow(0).GetCell(0).SetParagraph(SetTableParagraphInstanceSetting(document, firstXwpfTable, "报价单生成日期", ParagraphAlignment.LEFT, 10, false, 10, "#ff0000"));
firstXwpfTable.GetRow(0).GetCell(1).SetParagraph(SetTableParagraphInstanceSetting(document, firstXwpfTable, "付款方式", ParagraphAlignment.LEFT, 10, false, 10, "#ff0000"));
firstXwpfTable.GetRow(1).GetCell(0).SetParagraph(SetTableParagraphInstanceSetting(document, firstXwpfTable, Entity.createTime.ToString().Substring(0,10), ParagraphAlignment.LEFT, 40, false, 10));
firstXwpfTable.GetRow(1).GetCell(1).SetParagraph(SetTableParagraphInstanceSetting(document, firstXwpfTable, Entity.payTypeName.ToString(), ParagraphAlignment.LEFT, 40, false, 10));
firstXwpfTable.GetRow(2).GetCell(0).SetParagraph(SetTableParagraphInstanceSetting(document, firstXwpfTable, "报价单有效期", ParagraphAlignment.LEFT, 10, false, 10, "#ff0000"));
firstXwpfTable.GetRow(2).GetCell(1).SetParagraph(SetTableParagraphInstanceSetting(document, firstXwpfTable, "预计供货周期", ParagraphAlignment.LEFT, 10, false, 10, "#ff0000"));
firstXwpfTable.GetRow(3).GetCell(0).SetParagraph(SetTableParagraphInstanceSetting(document, firstXwpfTable, Entity.expiredTime.ToString(), ParagraphAlignment.LEFT, 0, false, 10));
firstXwpfTable.GetRow(3).GetCell(1).SetParagraph(SetTableParagraphInstanceSetting(document, firstXwpfTable, Entity.supplyTime.ToString() + "天", ParagraphAlignment.LEFT, 0, false, 10));
document.SetParagraph(ParagraphInstanceSetting(document, " ", false, 14, "微软雅黑", "#ff0000", UnderlinePatterns.Single, ParagraphAlignment.LEFT, ParagraphAlignment.RIGHT, 10, false, ""), DocIndex++);
document.SetParagraph(ParagraphInstanceSetting(document, " ", false, 14, "微软雅黑", "", UnderlinePatterns.None, ParagraphAlignment.LEFT, ParagraphAlignment.RIGHT, 10, false, ""), DocIndex++);
#endregion
RowIndex += 6;
}
if (Entity.customerExport == 1)
{
#region Table2
XWPFTable SecondXwpfTable = document.CreateTable(4, 2);//显示的行列数rows:3行,cols:4列
CT_Tbl secondTable = document.Document.body.GetTblArray()[TableIndex++];
secondTable.AddNewTblPr().jc = new CT_Jc();
secondTable.AddNewTblPr().jc.val = ST_Jc.center;//表在页面水平居中
secondTable.AddNewTblPr().AddNewTblW().w = "9000";//表宽度
secondTable.AddNewTblPr().AddNewTblW().type = ST_TblWidth.dxa;
CT_TcPr secondPr = SecondXwpfTable.GetRow(0).GetCell(0).GetCTTc().AddNewTcPr();
secondPr.tcW = new CT_TblWidth();
secondPr.tcW.w = "6000";//单元格宽
secondPr.tcW.type = ST_TblWidth.dxa;
secondPr = SecondXwpfTable.GetRow(0).GetCell(1).GetCTTc().AddNewTcPr();
secondPr.tcW = new CT_TblWidth();
secondPr.tcW.w = "3000";//单元格宽
secondPr.tcW.type = ST_TblWidth.dxa;
SecondXwpfTable.SetBottomBorder(XWPFBorderType.NONE, 1, 0, null);
SecondXwpfTable.SetLeftBorder(XWPFBorderType.NONE, 1, 0, null);
SecondXwpfTable.SetTopBorder(XWPFBorderType.NONE, 1, 0, null);
SecondXwpfTable.SetRightBorder(XWPFBorderType.NONE, 1, 0, null);
SecondXwpfTable.SetInsideHBorder(XWPFBorderType.NONE, 1, 0, null);
SecondXwpfTable.SetInsideVBorder(XWPFBorderType.NONE, 1, 0, null);

SecondXwpfTable.GetRow(0).GetCell(0).SetParagraph(SetTableParagraphInstanceSetting(document, SecondXwpfTable, "收货地址", ParagraphAlignment.LEFT, 20, false, 9, "#ff0000"));
SecondXwpfTable.GetRow(1).GetCell(0).SetParagraph(SetTableParagraphInstanceSetting(document, SecondXwpfTable, "客户名称:" + Entity.customerName.ToString() + "", ParagraphAlignment.LEFT, 30, false, 10, ""));
SecondXwpfTable.GetRow(2).GetCell(0).SetParagraph(SetTableParagraphInstanceSetting(document, SecondXwpfTable, "项目名称:" + Entity.boName.ToString() + "", ParagraphAlignment.LEFT, 30, false, 10, ""));
SecondXwpfTable.GetRow(2).GetCell(1).SetParagraph(SetTableParagraphInstanceSetting(document, SecondXwpfTable, "联系人:" + Entity.customerLinkName.ToString() + "", ParagraphAlignment.LEFT, 30, false, 10, ""));
SecondXwpfTable.GetRow(3).GetCell(0).SetParagraph(SetTableParagraphInstanceSetting(document, SecondXwpfTable, "地 址:" + Entity.customerAddress.ToString() + "", ParagraphAlignment.LEFT, 0, false, 10, ""));
SecondXwpfTable.GetRow(3).GetCell(1).SetParagraph(SetTableParagraphInstanceSetting(document, SecondXwpfTable, "电话:" + Entity.customerPhone.ToString() + "", ParagraphAlignment.LEFT, 0, false, 10));
document.SetParagraph(ParagraphInstanceSetting(document, " ", false, 14, "微软雅黑", "#ff0000", UnderlinePatterns.Single, ParagraphAlignment.LEFT, ParagraphAlignment.RIGHT, 10, false, ""), DocIndex++);
document.SetParagraph(ParagraphInstanceSetting(document, " ", false, 14, "微软雅黑", "", UnderlinePatterns.None, ParagraphAlignment.LEFT, ParagraphAlignment.RIGHT, 10, false, ""), DocIndex++);

#endregion
RowIndex += 6;
}
if (Entity.lenovoExport == 1)
{
#region Table3

XWPFTable ThreeXwpfTable = document.CreateTable(2, 3);//显示的行列数rows:3行,cols:4列
CT_Tbl threeTable = document.Document.body.GetTblArray()[TableIndex++];
threeTable.AddNewTblPr().jc = new CT_Jc();
threeTable.AddNewTblPr().jc.val = ST_Jc.center;//表在页面水平居中
threeTable.AddNewTblPr().AddNewTblW().w = "9000";//表宽度
threeTable.AddNewTblPr().AddNewTblW().type = ST_TblWidth.dxa;
CT_TcPr threePr = ThreeXwpfTable.GetRow(0).GetCell(0).GetCTTc().AddNewTcPr();
threePr.tcW = new CT_TblWidth();
threePr.tcW.w = "3000";//单元格宽
threePr.tcW.type = ST_TblWidth.dxa;
threePr = ThreeXwpfTable.GetRow(0).GetCell(1).GetCTTc().AddNewTcPr();
threePr.tcW = new CT_TblWidth();
threePr.tcW.w = "3000";//单元格宽
threePr.tcW.type = ST_TblWidth.dxa;
threePr = ThreeXwpfTable.GetRow(0).GetCell(2).GetCTTc().AddNewTcPr();
threePr.tcW = new CT_TblWidth();
threePr.tcW.w = "3000";//单元格宽
threePr.tcW.type = ST_TblWidth.dxa;
ThreeXwpfTable.SetBottomBorder(XWPFBorderType.NONE, 1, 0, null);
ThreeXwpfTable.SetLeftBorder(XWPFBorderType.NONE, 1, 0, null);
ThreeXwpfTable.SetTopBorder(XWPFBorderType.NONE, 1, 0, null);
ThreeXwpfTable.SetRightBorder(XWPFBorderType.NONE, 1, 0, null);
ThreeXwpfTable.SetInsideHBorder(XWPFBorderType.NONE, 1, 0, null);
ThreeXwpfTable.SetInsideVBorder(XWPFBorderType.NONE, 1, 0, null);
ThreeXwpfTable.GetRow(0).GetCell(0).SetParagraph(SetTableParagraphInstanceSetting(document, ThreeXwpfTable, "客户经理", ParagraphAlignment.LEFT, 0, false, 10, "#ff0000"));
ThreeXwpfTable.GetRow(0).GetCell(1).SetParagraph(SetTableParagraphInstanceSetting(document, ThreeXwpfTable, "联系电话", ParagraphAlignment.LEFT, 0, false, 10, "#ff0000"));
ThreeXwpfTable.GetRow(0).GetCell(2).SetParagraph(SetTableParagraphInstanceSetting(document, ThreeXwpfTable, "客户经理邮箱", ParagraphAlignment.LEFT, 0, false, 10, "#ff0000"));
ThreeXwpfTable.GetRow(1).GetCell(0).SetParagraph(SetTableParagraphInstanceSetting(document, ThreeXwpfTable, Entity.lenovoLinkName.ToString(), ParagraphAlignment.LEFT, 20, false, 10, ""));
ThreeXwpfTable.GetRow(1).GetCell(1).SetParagraph(SetTableParagraphInstanceSetting(document, ThreeXwpfTable, Entity.lenovoPhone.ToString(), ParagraphAlignment.LEFT, 20, false, 10, ""));
ThreeXwpfTable.GetRow(1).GetCell(2).SetParagraph(SetTableParagraphInstanceSetting(document, ThreeXwpfTable, Entity.lenovoEmail.ToString(), ParagraphAlignment.LEFT, 20, false, 10, ""));
document.SetParagraph(ParagraphInstanceSetting(document, " ", false, 14, "微软雅黑", "#ff0000", UnderlinePatterns.Single, ParagraphAlignment.LEFT, ParagraphAlignment.RIGHT, 10, false, ""), DocIndex++);
#endregion
RowIndex += 3;
}
if (Entity.invoiceExport == 1)
{
#region Table

XWPFTable Table = document.CreateTable(2, 3);//显示的行列数rows:3行,cols:4列
CT_Tbl CtTable = document.Document.body.GetTblArray()[TableIndex++];
CtTable.AddNewTblPr().jc = new CT_Jc();
CtTable.AddNewTblPr().jc.val = ST_Jc.center;//表在页面水平居中
CtTable.AddNewTblPr().AddNewTblW().w = "9000";//表宽度
CtTable.AddNewTblPr().AddNewTblW().type = ST_TblWidth.dxa;
CT_TcPr CtPr = Table.GetRow(0).GetCell(0).GetCTTc().AddNewTcPr();
CtPr.tcW = new CT_TblWidth();
CtPr.tcW.w = "3000";//单元格宽
CtPr.tcW.type = ST_TblWidth.dxa;
CtPr = Table.GetRow(0).GetCell(1).GetCTTc().AddNewTcPr();
CtPr.tcW = new CT_TblWidth();
CtPr.tcW.w = "3000";//单元格宽
CtPr.tcW.type = ST_TblWidth.dxa;
CtPr = Table.GetRow(0).GetCell(2).GetCTTc().AddNewTcPr();
CtPr.tcW = new CT_TblWidth();
CtPr.tcW.w = "3000";//单元格宽
CtPr.tcW.type = ST_TblWidth.dxa;
Table.SetBottomBorder(XWPFBorderType.NONE, 1, 0, null);
Table.SetLeftBorder(XWPFBorderType.NONE, 1, 0, null);
Table.SetTopBorder(XWPFBorderType.NONE, 1, 0, null);
Table.SetRightBorder(XWPFBorderType.NONE, 1, 0, null);
Table.SetInsideHBorder(XWPFBorderType.NONE, 1, 0, null);
Table.SetInsideVBorder(XWPFBorderType.NONE, 1, 0, null);
Table.GetRow(0).GetCell(0).SetParagraph(SetTableParagraphInstanceSetting(document, Table, "发票形式", ParagraphAlignment.LEFT, 0, false, 10, "#ff0000"));
Table.GetRow(0).GetCell(1).SetParagraph(SetTableParagraphInstanceSetting(document, Table, "发票收取方式", ParagraphAlignment.LEFT, 0, false, 10, "#ff0000"));
Table.GetRow(1).GetCell(0).SetParagraph(SetTableParagraphInstanceSetting(document, Table, Entity.InvoiceTypeName.ToString(), ParagraphAlignment.LEFT, 20, false, 10, ""));
Table.GetRow(1).GetCell(1).SetParagraph(SetTableParagraphInstanceSetting(document, Table, Entity.InvoiceReceiveTypeName.ToString(), ParagraphAlignment.LEFT, 20, false, 10, ""));
document.SetParagraph(ParagraphInstanceSetting(document, " ", false, 14, "微软雅黑", "#ff0000", UnderlinePatterns.Single, ParagraphAlignment.LEFT, ParagraphAlignment.RIGHT, 10, false, ""), DocIndex++);
#endregion
RowIndex += 3;
}
#region Table4 价格汇总
document.SetParagraph(ParagraphInstanceSetting(document, "|价格汇总", true, 15, "微软雅黑", "#ff0000", UnderlinePatterns.None, ParagraphAlignment.LEFT, ParagraphAlignment.RIGHT, 10, false, ""), DocIndex++);
document.SetParagraph(ParagraphInstanceSetting(document, " ", false, 14, "微软雅黑", "", UnderlinePatterns.None, ParagraphAlignment.LEFT, ParagraphAlignment.RIGHT, 10, false, ""), DocIndex++);

XWPFTable FourXwpfTable = document.CreateTable(product.Count + 2, 5);
CT_Tbl FourTable = document.Document.body.GetTblArray()[TableIndex++];

FourTable.AddNewTblPr().jc = new CT_Jc();
FourTable.AddNewTblPr().jc.val = ST_Jc.center;//表在页面水平居中
FourTable.AddNewTblPr().AddNewTblW().w = "9000";//表宽度
FourTable.AddNewTblPr().AddNewTblW().type = ST_TblWidth.dxa;
CT_TcPr fourPr = new CT_TcPr();
XWPFTableRow FourxwpfTable;

//固定表格宽度
for (int d = 0; d < product.Count + 2; d++)
{
fourPr = FourXwpfTable.GetRow(d).GetCell(0).GetCTTc().AddNewTcPr();
fourPr.tcW = new CT_TblWidth();
fourPr.tcW.w = "2500";//单元格宽
fourPr.tcW.type = ST_TblWidth.dxa;
fourPr = FourXwpfTable.GetRow(d).GetCell(1).GetCTTc().AddNewTcPr();
fourPr.tcW = new CT_TblWidth();
fourPr.tcW.w = "3500";//单元格宽
fourPr.tcW.type = ST_TblWidth.dxa;
fourPr = FourXwpfTable.GetRow(d).GetCell(2).GetCTTc().AddNewTcPr();
fourPr.tcW = new CT_TblWidth();
fourPr.tcW.w = "800";//单元格宽
fourPr.tcW.type = ST_TblWidth.dxa;
fourPr = FourXwpfTable.GetRow(d).GetCell(3).GetCTTc().AddNewTcPr();
fourPr.tcW = new CT_TblWidth();
fourPr.tcW.w = "1000";//单元格宽
fourPr.tcW.type = ST_TblWidth.dxa;
fourPr = FourXwpfTable.GetRow(d).GetCell(4).GetCTTc().AddNewTcPr();
fourPr.tcW = new CT_TblWidth();
fourPr.tcW.w = "1000";//单元格宽

fourPr.tcW.type = ST_TblWidth.dxa;

//设置表格时候允许跨页断行
FourxwpfTable= FourXwpfTable.GetRow(d);
FourxwpfTable.IsCantSplitRow = true;
}
#region 设置样式
FourXwpfTable.SetBottomBorder(XWPFBorderType.SINGLE, 10, 0, "pink");
FourXwpfTable.SetLeftBorder(XWPFBorderType.SINGLE, 10, 0, "pink");
FourXwpfTable.SetTopBorder(XWPFBorderType.SINGLE, 10, 0, "pink");
FourXwpfTable.SetRightBorder(XWPFBorderType.SINGLE, 10, 0, "pink");
FourXwpfTable.SetInsideHBorder(XWPFBorderType.SINGLE, 10, 0, "pink");
FourXwpfTable.SetInsideVBorder(XWPFBorderType.SINGLE, 10, 0, "pink");
FourXwpfTable.GetRow(0).GetCell(0).SetParagraph(SetTableParagraphInstanceSetting(document, FourXwpfTable, "产品名称", ParagraphAlignment.LEFT, 30, false, 10, ""));
FourXwpfTable.GetRow(0).GetCell(1).SetParagraph(SetTableParagraphInstanceSetting(document, FourXwpfTable, "配置", ParagraphAlignment.LEFT, 30, false, 10, ""));
FourXwpfTable.GetRow(0).GetCell(2).SetParagraph(SetTableParagraphInstanceSetting(document, FourXwpfTable, "数量", ParagraphAlignment.LEFT, 30, false, 10, ""));
FourXwpfTable.GetRow(0).GetCell(3).SetParagraph(SetTableParagraphInstanceSetting(document, FourXwpfTable, "单价(含税)", ParagraphAlignment.LEFT, 30, false, 10, ""));
FourXwpfTable.GetRow(0).GetCell(4).SetParagraph(SetTableParagraphInstanceSetting(document, FourXwpfTable, "金额(含税)", ParagraphAlignment.LEFT, 30, false, 10, ""));
RowIndex += 3;
#endregion
int Num = 0;
int TotalPrice = 0;

for (int i = 0; i < product.Count(); i++)
{
Num += product[i].quantity;
TotalPrice += product[i].quantity * product[i].productPrice;

FourXwpfTable.GetRow(i + 1).GetCell(0).SetParagraph(SetTableParagraphInstanceSetting(document, FourXwpfTable, product[i].productName.ToString(), ParagraphAlignment.LEFT, -10, false, 10, ""));
FourXwpfTable.GetRow(i + 1).GetCell(1).SetParagraph(SetTableParagraphInstanceSetting(document, FourXwpfTable, product[i].majorParts.ToString(), ParagraphAlignment.LEFT, -10, false, 10, ""));
FourXwpfTable.GetRow(i + 1).GetCell(2).SetParagraph(SetTableParagraphInstanceSetting(document, FourXwpfTable, product[i].quantity.ToString(), ParagraphAlignment.LEFT, -10, false, 10, ""));
FourXwpfTable.GetRow(i + 1).GetCell(3).SetParagraph(SetTableParagraphInstanceSetting(document, FourXwpfTable, product[i].productPrice.ToString(), ParagraphAlignment.LEFT, -10, false, 10, ""));
FourXwpfTable.GetRow(i + 1).GetCell(4).SetParagraph(SetTableParagraphInstanceSetting(document, FourXwpfTable, "¥" + product[i].productTotalPrice.ToString(), ParagraphAlignment.LEFT, -10, false, 10, ""));
FourXwpfTable.GetRow(i + 1).GetCell(4).SetColor("#EEEEEE");
}
FourXwpfTable.GetRow(product.Count() + 1).GetCell(0).SetParagraph(SetTableParagraphInstanceSetting(document, FourXwpfTable, "总计", ParagraphAlignment.LEFT, 30, false, 10, ""));
FourXwpfTable.GetRow(product.Count() + 1).GetCell(1).SetParagraph(SetTableParagraphInstanceSetting(document, FourXwpfTable, "", ParagraphAlignment.LEFT, 30, false, 10, ""));
FourXwpfTable.GetRow(product.Count() + 1).GetCell(2).SetParagraph(SetTableParagraphInstanceSetting(document, FourXwpfTable, "", ParagraphAlignment.LEFT, 30, false, 10, ""));
FourXwpfTable.GetRow(product.Count() + 1).GetCell(3).SetParagraph(SetTableParagraphInstanceSetting(document, FourXwpfTable, "", ParagraphAlignment.LEFT, 30, false, 10, ""));
FourXwpfTable.GetRow(product.Count() + 1).GetCell(4).SetParagraph(SetTableParagraphInstanceSetting(document, FourXwpfTable, "¥" + TotalPrice.ToString(), ParagraphAlignment.LEFT, 30, false, 10, ""));
FourXwpfTable.GetRow(product.Count() + 1).GetCell(4).SetColor("#EEEEEE");
FourXwpfTable.GetRow(product.Count()).GetCell(0).SetBorderBottom(XWPFBorderType.SINGLE, 10, 0, "pink");
FourXwpfTable.GetRow(product.Count()).GetCell(1).SetBorderBottom(XWPFBorderType.SINGLE, 10, 0, "pink");
FourXwpfTable.GetRow(product.Count()).GetCell(2).SetBorderBottom(XWPFBorderType.SINGLE, 10, 0, "pink");
FourXwpfTable.GetRow(product.Count()).GetCell(3).SetBorderBottom(XWPFBorderType.SINGLE, 10, 0, "pink");
FourXwpfTable.GetRow(product.Count()).GetCell(4).SetBorderBottom(XWPFBorderType.SINGLE, 10, 0, "pink");

document.SetParagraph(ParagraphInstanceSetting(document, " ", false, 14, "微软雅黑", "", UnderlinePatterns.None, ParagraphAlignment.LEFT, ParagraphAlignment.RIGHT, 10, false, ""), DocIndex++);
document.SetParagraph(ParagraphInstanceSetting(document, " ", false, 14, "微软雅黑", "", UnderlinePatterns.None, ParagraphAlignment.LEFT, ParagraphAlignment.RIGHT, 10, false, ""), DocIndex++);

#endregion
#region Table5 温馨提示

document.SetParagraph(ParagraphInstanceSetting(document, "|温馨提示", true, 15, "微软雅黑", "#ff0000", UnderlinePatterns.None, ParagraphAlignment.LEFT, ParagraphAlignment.RIGHT, 10, false, ""), DocIndex++);
document.SetParagraph(ParagraphInstanceSetting(document, " ", false, 14, "微软雅黑", "", UnderlinePatterns.None, ParagraphAlignment.LEFT, ParagraphAlignment.RIGHT, 10, false, ""), DocIndex++);
XWPFTable FiveXwpfTable = document.CreateTable(3, 1);
CT_Tbl fiveTable = document.Document.body.GetTblArray()[TableIndex++];
fiveTable.AddNewTblPr().jc = new CT_Jc();
fiveTable.AddNewTblPr().jc.val = ST_Jc.center;//表在页面水平居中
fiveTable.AddNewTblPr().AddNewTblW().w = "9000";//表宽度
fiveTable.AddNewTblPr().AddNewTblW().type = ST_TblWidth.dxa;
XWPFTableRow FiveTavleXwpf = FiveXwpfTable.GetRow(0);
FiveTavleXwpf.IsCantSplitRow = true;
FiveTavleXwpf = FiveXwpfTable.GetRow(1);
FiveTavleXwpf.IsCantSplitRow = true;
FiveTavleXwpf = FiveXwpfTable.GetRow(2);
FiveTavleXwpf.IsCantSplitRow = true;
CT_TcPr fivePr = FiveXwpfTable.GetRow(0).GetCell(0).GetCTTc().AddNewTcPr();
fivePr.tcW = new CT_TblWidth();
fivePr.tcW.w = "9000";//单元格宽
fivePr.tcW.type = ST_TblWidth.dxa;
XWPFTableRow fivexwpfTable = FourXwpfTable.GetRow(0);
fivexwpfTable.IsCantSplitRow = true;

FiveXwpfTable.SetBottomBorder(XWPFBorderType.SINGLE, 13, 0, "pink");
FiveXwpfTable.SetLeftBorder(XWPFBorderType.SINGLE, 13, 0, "pink");
FiveXwpfTable.SetTopBorder(XWPFBorderType.SINGLE, 13, 0, "pink");
FiveXwpfTable.SetRightBorder(XWPFBorderType.SINGLE, 13, 0, "pink");
FiveXwpfTable.SetInsideHBorder(XWPFBorderType.SINGLE, 1, 0, "pink");
FiveXwpfTable.SetInsideVBorder(XWPFBorderType.SINGLE, 1, 0, "pink");
FiveXwpfTable.GetRow(1).GetCell(0).SetBorderTop(XWPFBorderType.NONE, 1, 0, null);
FiveXwpfTable.GetRow(2).GetCell(0).SetBorderTop(XWPFBorderType.NONE, 1, 0, null);
FiveXwpfTable.GetRow(1).GetCell(0).SetBorderBottom(XWPFBorderType.NONE, 1, 0, null);
FiveXwpfTable.GetRow(0).GetCell(0).SetBorderBottom(XWPFBorderType.NONE, 1, 0, null);
FiveXwpfTable.GetRow(0).GetCell(0).SetParagraph(SetTableParagraphInstanceSetting(document, FiveXwpfTable, "1)本报价未考虑具体交易条件,价格为预付贷款条件,且不含任何未列部件和服务费用.请联系当地联想客户经理,以确保获取产品信息和价格.最终成交价格以联想与客户签署的书面合同为准.", ParagraphAlignment.LEFT, -10, false, 9, ""));
FiveXwpfTable.GetRow(1).GetCell(0).SetParagraph(SetTableParagraphInstanceSetting(document, FiveXwpfTable, "2)本报价所含全部内容为联想保密信息.未经联想书面许可不得对外披露、复制、传播或以其它任何方式使用.", ParagraphAlignment.LEFT, -10, false, 9, ""));
FiveXwpfTable.GetRow(2).GetCell(0).SetParagraph(SetTableParagraphInstanceSetting(document, FiveXwpfTable, "3)获取产品详细介绍请登录联想大客户官网http://b2b.lenovo.com.cn", ParagraphAlignment.LEFT, 30, false, 9, ""));
if(product.Count>1)
{
document.SetParagraph(BreakPage(document), DocIndex++);
}

#endregion
#region Table6

if (Parts.Count > 0)
{
document.SetParagraph(ParagraphInstanceSetting(document, "|报价单描述", true, 15, "微软雅黑", "#ff0000", UnderlinePatterns.None, ParagraphAlignment.LEFT, ParagraphAlignment.RIGHT, 10, false, ""), DocIndex++);
document.SetParagraph(ParagraphInstanceSetting(document, " ", false, 14, "微软雅黑", "", UnderlinePatterns.None, ParagraphAlignment.LEFT, ParagraphAlignment.RIGHT, 10, false, ""), DocIndex++);
}
for (int k = 0; k < Entity.projects.Count(); k++)
{
for (int i = 0; i < Entity.projects[k].products.Count(); i++)
{
if (Entity.projects[k].products[i].parts.Count() == 0)
{
continue;
}
XWPFTable SixXwpfTable = document.CreateTable(Entity.projects[k].products[i].parts.Count() + 3, 5);
CT_Tbl sixTable = document.Document.body.GetTblArray()[TableIndex++];
sixTable.AddNewTblPr().jc = new CT_Jc();
sixTable.AddNewTblPr().jc.val = ST_Jc.center;//表在页面水平居中
sixTable.AddNewTblPr().AddNewTblW().w = "9000";//表宽度
sixTable.AddNewTblPr().AddNewTblW().type = ST_TblWidth.dxa;
CT_TcPr sixPr = SixXwpfTable.GetRow(0).GetCell(0).GetCTTc().AddNewTcPr();
sixPr.tcW = new CT_TblWidth();
sixPr.tcW.w = "3000";//单元格宽
sixPr.tcW.type = ST_TblWidth.dxa;
sixPr = SixXwpfTable.GetRow(0).GetCell(1).GetCTTc().AddNewTcPr();
sixPr.tcW = new CT_TblWidth();
sixPr.tcW.w = "2000";//单元格宽
sixPr.tcW.type = ST_TblWidth.dxa;
sixPr = SixXwpfTable.GetRow(0).GetCell(2).GetCTTc().AddNewTcPr();
sixPr.tcW = new CT_TblWidth();
sixPr.tcW.w = "1500";//单元格宽
sixPr.tcW.type = ST_TblWidth.dxa;
sixPr = SixXwpfTable.GetRow(0).GetCell(3).GetCTTc().AddNewTcPr();
sixPr.tcW = new CT_TblWidth();
sixPr.tcW.w = "1500";//单元格宽
sixPr.tcW.type = ST_TblWidth.dxa;
sixPr = SixXwpfTable.GetRow(0).GetCell(4).GetCTTc().AddNewTcPr();
sixPr.tcW = new CT_TblWidth();
sixPr.tcW.w = "1000";//单元格宽
sixPr.tcW.type = ST_TblWidth.dxa;
SixXwpfTable.SetBottomBorder(XWPFBorderType.NONE, 1, 0, null);
SixXwpfTable.SetLeftBorder(XWPFBorderType.NONE, 1, 0, null);
SixXwpfTable.SetTopBorder(XWPFBorderType.NONE, 1, 0, null);
SixXwpfTable.SetRightBorder(XWPFBorderType.NONE, 1, 0, null);
SixXwpfTable.SetInsideHBorder(XWPFBorderType.NONE, 1, 0, null);
SixXwpfTable.SetInsideVBorder(XWPFBorderType.NONE, 1, 0, null);
MYMergeCells(SixXwpfTable, 0, 0, 0, Entity.projects[k].products[i].parts.Count() + 2);
MYMergeCells(SixXwpfTable, 1, 1, 0, 1);

if (fileJArray.fsp.bomPic.Where(p => p.bomCode == Entity.projects[k].products[i].bomCode).Count() > 0)
{
SixXwpfTable.GetRow(0).GetCell(0).SetParagraph(SetWritePicture(document, SixXwpfTable, fileJArray.fsp.bomPic.Where(p => p.bomCode == Entity.projects[k].products[i].bomCode).FirstOrDefault().bomPic, ParagraphAlignment.CENTER, NPOI.XWPF.UserModel.PictureType.JPEG, 170 * 9525, 170 * 9525));
}
else
{
SixXwpfTable.GetRow(0).GetCell(0).SetParagraph(SetTableParagraphInstanceSetting(document, SixXwpfTable, "", ParagraphAlignment.LEFT, -10, false, 10, "#ff0000"));
}
SixXwpfTable.GetRow(0).GetCell(2).SetParagraph(SetTableParagraphInstanceSetting(document, SixXwpfTable, "数量", ParagraphAlignment.LEFT, -10, false, 10, ""));
SixXwpfTable.GetRow(0).GetCell(3).SetParagraph(SetTableParagraphInstanceSetting(document, SixXwpfTable, "单价", ParagraphAlignment.LEFT, -10, false, 10, ""));
SixXwpfTable.GetRow(0).GetCell(4).SetParagraph(SetTableParagraphInstanceSetting(document, SixXwpfTable, "金额", ParagraphAlignment.LEFT, -10, false, 10, ""));
SixXwpfTable.GetRow(0).GetCell(1).SetParagraph(SetTableParagraphInstanceSetting(document, SixXwpfTable, Entity.projects[k].products[i].productName.ToString(), ParagraphAlignment.LEFT, -10, false, 10, "#ff0000"));
SixXwpfTable.GetRow(1).GetCell(2).SetParagraph(SetTableParagraphInstanceSetting(document, SixXwpfTable, Entity.projects[k].products[i].quantity.ToString(), ParagraphAlignment.LEFT, -10, false, 10, ""));
SixXwpfTable.GetRow(1).GetCell(3).SetParagraph(SetTableParagraphInstanceSetting(document, SixXwpfTable, Entity.projects[k].products[i].productPrice.ToString(), ParagraphAlignment.LEFT, -10, false, 10, ""));
SixXwpfTable.GetRow(1).GetCell(4).SetParagraph(SetTableParagraphInstanceSetting(document, SixXwpfTable, Entity.projects[k].products[i].productTotalPrice.ToString(), ParagraphAlignment.LEFT, -10, false, 10, ""));
// SixXwpfTable.GetRow(1).GetCell(1).AddParagraph().CreateRun();

SixXwpfTable.GetRow(2).MergeCells(1, 2);
SixXwpfTable.GetRow(2).MergeCells(2, 3);
SixXwpfTable.GetRow(2).GetCell(1).SetColor("#EEEEEE");
SixXwpfTable.GetRow(2).GetCell(2).SetColor("#EEEEEE");
SixXwpfTable.GetRow(2).GetCell(1).SetParagraph(SetTableParagraphInstanceSetting(document, SixXwpfTable, "标签", ParagraphAlignment.LEFT, -10, true, 10, ""));
SixXwpfTable.GetRow(2).GetCell(2).SetParagraph(SetTableParagraphInstanceSetting(document, SixXwpfTable, "描述", ParagraphAlignment.LEFT, -10, true, 10, ""));

for (int s = 0; s < Entity.projects[k].products[i].parts.Count(); s++)
{
SixXwpfTable.GetRow(3 + s).MergeCells(1, 2);
SixXwpfTable.GetRow(3 + s).MergeCells(2, 3);
SixXwpfTable.GetRow(3 + s).GetCell(1).SetParagraph(SetTableParagraphInstanceSetting(document, SixXwpfTable, Entity.projects[k].products[i].parts[s].r3Name.ToString(), ParagraphAlignment.LEFT, -10, false, 10, ""));
SixXwpfTable.GetRow(3 + s).GetCell(2).SetParagraph(SetTableParagraphInstanceSetting(document, SixXwpfTable, Entity.projects[k].products[i].parts[s].r3VName.ToString(), ParagraphAlignment.LEFT, -10, false, 10, ""));
}
document.SetParagraph(ParagraphInstanceSetting(document, " ", false, 14, "微软雅黑", "", UnderlinePatterns.None, ParagraphAlignment.LEFT, ParagraphAlignment.RIGHT, 10, false, ""), DocIndex++);
document.SetParagraph(ParagraphInstanceSetting(document, " ", false, 14, "微软雅黑", "", UnderlinePatterns.None, ParagraphAlignment.LEFT, ParagraphAlignment.RIGHT, 10, false, ""), DocIndex++);
document.SetParagraph(ParagraphInstanceSetting(document, " ", false, 14, "微软雅黑", "", UnderlinePatterns.None, ParagraphAlignment.LEFT, ParagraphAlignment.RIGHT, 10, false, ""), DocIndex++);
document.SetParagraph(ParagraphInstanceSetting(document, " ", false, 14, "微软雅黑", "#ff0000", UnderlinePatterns.Single, ParagraphAlignment.LEFT, ParagraphAlignment.RIGHT, 10, false, ""), DocIndex++);
document.SetParagraph(ParagraphInstanceSetting(document, " ", false, 14, "微软雅黑", "", UnderlinePatterns.None, ParagraphAlignment.LEFT, ParagraphAlignment.RIGHT, 10, false, ""), DocIndex++);
document.SetParagraph(ParagraphInstanceSetting(document, " ", false, 14, "微软雅黑", "", UnderlinePatterns.None, ParagraphAlignment.LEFT, ParagraphAlignment.RIGHT, 10, false, ""), DocIndex++);
document.SetParagraph(ParagraphInstanceSetting(document, " ", false, 14, "微软雅黑", "", UnderlinePatterns.None, ParagraphAlignment.LEFT, ParagraphAlignment.RIGHT, 10, false, ""), DocIndex++);
}
}
#endregion
#region 广告位
if (fileJArray.code == 200 && fileJArray.fsp.adImage.Count() > 0)
{
document.SetParagraph(BreakPage(document), DocIndex++);
document.SetParagraph(ParagraphInstanceSetting(document, "|增值服务 ", true, 15, "微软雅黑", "#ff0000", UnderlinePatterns.None, ParagraphAlignment.LEFT, ParagraphAlignment.RIGHT, 10, false, ""), DocIndex++);
document.SetParagraph(ParagraphInstanceSetting(document, " ", false, 14, "微软雅黑", "", UnderlinePatterns.None, ParagraphAlignment.LEFT, ParagraphAlignment.RIGHT, 10, false, ""), DocIndex++);
XWPFTable ImageXwpfTable = document.CreateTable(1, 1);
CT_Tbl ImageTable = document.Document.body.GetTblArray()[TableIndex++];
ImageTable.AddNewTblPr().jc = new CT_Jc();
ImageTable.AddNewTblPr().jc.val = ST_Jc.center;//表在页面水平居中
ImageTable.AddNewTblPr().AddNewTblW().w = "9000";//表宽度
ImageTable.AddNewTblPr().AddNewTblW().type = ST_TblWidth.dxa;
CT_TcPr ImagePr = ImageXwpfTable.GetRow(0).GetCell(0).GetCTTc().AddNewTcPr();
ImagePr.tcW = new CT_TblWidth();
ImagePr.tcW.w = "9000";//单元格宽
ImagePr.tcW.type = ST_TblWidth.dxa;
ImageXwpfTable.SetBottomBorder(XWPFBorderType.NONE, 13, 0, "pink");
ImageXwpfTable.SetLeftBorder(XWPFBorderType.NONE, 13, 0, "pink");
ImageXwpfTable.SetTopBorder(XWPFBorderType.NONE, 13, 0, "pink");
ImageXwpfTable.SetRightBorder(XWPFBorderType.NONE, 13, 0, "pink");
ImageXwpfTable.SetInsideHBorder(XWPFBorderType.NONE, 1, 0, "pink");
ImageXwpfTable.SetInsideVBorder(XWPFBorderType.NONE, 1, 0, "pink");
ImageXwpfTable.GetRow(0).GetCell(0).SetParagraph(SetWritePicture(document, ImageXwpfTable, fileJArray.fsp.adImage.Count() > 0 ? fileJArray.fsp.adImage : "", ParagraphAlignment.RIGHT, NPOI.XWPF.UserModel.PictureType.PNG, 600 * 9525, 800 * 9525));
}
#endregion
document.Write(stream);
filePath = Path.Combine(uploadPath, fileName);
}

总结:

   经历了小一周的摸索,为了实现想要的样子,通过不断查阅与自己的理解终于达到了想要的效果,感谢那些写资料的人让我少走一些弯路,在这里记录下自己的一些收获,心得分享给大家,希望会帮助到大家

C#使用NPOI对Word文档进行导出操作的dll最新版2.5.1的更多相关文章

  1. word文档的导出(用freemarker模板导出)(桃)

    1.将要导出的word文档另存为xml格式的 2.用文档编辑器打开(如:notepad++),将要展示的数据用${name}的形式替换,“name”对应数据库中的字段 3.根据模板生成 package ...

  2. 利用NPOI生成word文档(c#)

    WordTest.aspx.cs using System; using System.IO; using System.Text; using System.Web; using System.We ...

  3. 使用NPOI读取Word文档内容并进行修改

    前言 网上使用NPOI读取Word文件的例子现在也不少,本文就是参考网上大神们的例子进行修改以适应自己需求的. 参考博文 http://www.cnblogs.com/mahongbiao/p/376 ...

  4. .Net实现Word文档及导出

    参考网址: http://www.jb51.net/article/25062.htm(实用性) http://wenku.baidu.com/link?url=44O7Dua49DrZ-PF2QU7 ...

  5. 有哪位大侠操作过NPOI生成word文档,如何设置页眉页脚距离顶部和底部距离?

    #region 1.创建文档(页眉.页脚) XWPFDocument doc = new XWPFDocument(); //页面设置 A4:w=11906 h=16838 doc.Document. ...

  6. 利用Aspose.Word控件和Aspose.Cell控件,实现Word文档和Excel文档的模板化导出

    我们知道,一般都导出的Word文档或者Excel文档,基本上分为两类,一类是动态生成全部文档的内容方式,一种是基于固定模板化的内容输出,后者在很多场合用的比较多,这也是企业报表规范化的一个体现. 我的 ...

  7. VC操作WORD文档总结

    一.写在开头 最近研究word文档的解析技术,我本身是VC的忠实用户,看到C#里面操作WORD这么舒服,同时也看到单位有一些需求,就想尝试一下,结果没想到里面的技术点真不少,同时网络上的共享资料很多, ...

  8. C# - 操作Word文档小实验

    前言 本篇主要记录:VS2019 WinFrm桌面应用程序实现对Word文档的简单操作. 准备工作 搭建WinFrm前台界面 添加必要的控件,如下图 NuGet包管理器 安装Microsoft.Off ...

  9. C#/VB.NET 比较两个Word文档差异

    本文以C#和VB.NET代码为例,来介绍如何对比两个Word文档差异.程序中使用最新版的Spire.Doc for .NET 版本8.8.2.编辑代码前,先在VS程序中添加引用Spire.Doc.dl ...

随机推荐

  1. Logstash下字段以及嵌套Json字段类型转换

    前言 从filebeat传输到Logstash的数据,某个字段需要由string类型装换成float类型.但是不管怎么改logstash的配置文件都不生效,其实官方文档都有,但是具体细节方面的东西就得 ...

  2. @loj - 3120@ 「CTS2019 | CTSC2019」珍珠

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 有 \(n\) 个在范围 \([1, D]\) 内的整数均匀随机 ...

  3. 面试:在面试中关于List(ArrayList、LinkedList)集合会怎么问呢?你该如何回答呢?

    前言 在一开始基础面的时候,很多面试官可能会问List集合一些基础知识,比如: ArrayList默认大小是多少,是如何扩容的? ArrayList和LinkedList的底层数据结构是什么? Arr ...

  4. c++的两个冒号::四个点是什么意思,什么作用呢?

    c++的两个冒号::四个点是什么意思,什么作用呢? 双冒号(::)用法 (1)表示“域操作符”例:声明了一个类A,类A里声明了一个成员函数void f(),但没有在类的声明里给出f的定义,那么在类外定 ...

  5. python的坑--你知道吗?

    python的坑--你知道吗? 1.列表的坑 坑的地方是:因为列表用pop之后,后面的索引都会自动减一 # 列表的坑之一 list1 = ['python','java','php','c','c++ ...

  6. 特性速览| Apache Hudi 0.5.3版本正式发布

    1. 下载连接 源代码下载:Apache Hudi 0.5.3 Source Release (asc, sha512) 0.5.3版本相关jar包地址:https://repository.apac ...

  7. Jmeter接口测试,往MySQL数据库写数据时,中文显示???

    调Jmeter接口测试,请求字段输入中文,查看数据库插入情况, 发现数据库显示    ???

  8. Ubuntu图形界面root登录出现“sorry, that didn't work please try again”

    ssh登录主机执行下vim /etc/pam.d/gdm-autologin 注释行 "auth requied pam_succeed_if.so user != root quiet s ...

  9. 基于flink和drools的实时日志处理

    1.背景 日志系统接入的日志种类多.格式复杂多样,主流的有以下几种日志: filebeat采集到的文本日志,格式多样 winbeat采集到的操作系统日志 设备上报到logstash的syslog日志 ...

  10. MFC 结束线程

    在wtl工程中定义一个现成,如下:DWORD WINAPI ThreadFunc( LPVOID pParam ){if( g_pMainlg )g_pMainlg->DoEnumNetwork ...