用户登录
用户注册

分享至

使用npoi将数据导出为word格式里的

  • 作者: 小怪兽i37508886
  • 来源: 51数据库
  • 2020-04-21

1.npoi如何使导出到excel的合并单元格里的数据居中呢

n行合并,应该是一起合并的,并不是两行两行合并。

要实现,算法上要想一下。确定每组的开始行号跟结束行号,由这两个值来合并int start=…;//合并开始行号int end=…;//合并结束行号if(start!=end)//该组开始行号跟结束行号相同时候,该组只有一行,不用合并。

不等才合并{CellRangeAddress region = new CellRangeAddress(start,end,j,j);Sheet.AddMergedRegion(region);}上面开始行号跟结束行号,就需要在循环中判断,并设置。这只是思路,供参考。

2..net 页面导出为word

npoi可以导出为docx格式的word文档,具体怎么用表格,没有试过,给你一段导出的代码,你可以参考

using (DocX document = DocX.Create(Server.MapPath("~/Temp/ScoreResultDoc") + "/ScoreResultDoc.docx"))

{

Paragraph p = document.InsertParagraph();

// Append some text and add formatting.

p.Append("河北省信用档案\n")

.Font(new FontFamily("Times New Roman"))

.FontSize(24)

.Color(Color.Black)

.Bold();

p.Alignment = Alignment.center;

//p.Direction = Direction;

p.Append("记分告知单\n")

.Font(new FontFamily("Times New Roman"))

.FontSize(24)

.Color(Color.Black)

.Bold();

p.Alignment = Alignment.center;

Paragraph p1 = document.InsertParagraph();

//p1.Append(" ")

// .Font(new FontFamily("Times New Roman"))

// .FontSize(14)

// .Color(Color.Black)

// .Bold();

//float ff = 14.0f * 1.0f / 2.83f / 10.0f;

p1.IndentationFirstLine = f14;

p1.Append(businessName).UnderlineStyle(UnderlineStyle.singleLine)

.Font(new FontFamily("宋体"))

.FontSize(14)

.Color(Color.Black)

.Bold();

p1.Alignment = Alignment.left;

p1.Append(": 编号:[ ]号")

.Font(new FontFamily("宋体"))

.FontSize(14);

p1.Alignment = Alignment.left;

p1.SetLineSpacing(LineSpacingType.Line, 1.5f);

document.Save();

}

转载请注明出处51数据库 » 使用npoi将数据导出为word格式里的

软件
前端设计
程序设计
Java相关