public void aaa()
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.Add("a");
dt.Columns.Add("b");
DataRow dr = dt.NewRow();
dr["a"] = "ay";
dr["b"] = "by";
dt.Rows.Add(dr);
XWPFDocument doc = new XWPFDocument();
XWPFTable table = doc.CreateTable(dt.Rows.Count + 1, dt.Columns.Count);//声明整个表的大小 +1是为了增加一行表头
//增加表头信息
for (int i = 0; i < dt.Columns.Count; i++)
{
table.GetRow(0).GetCell(i).SetText(dt.Columns[i].ColumnName);
}
//增加内容信息
for (int i = 0; i < dt.Rows.Count; i++)
{
for (int j = 0; j < dt.Columns.Count; j++)
{
string Vt = Convert.ToString(dt.Rows[i][j]);
table.GetRow(i + 1).GetCell(j).SetText(Vt);
}
}
string FilePath = "D:\\work\\aaa\\Word";
if (!Directory.Exists(FilePath))
Directory.CreateDirectory(FilePath);
FilePath = FilePath + "\\测试word文档.doc";
FileStream Fs = new FileStream(FilePath, FileMode.OpenOrCreate);
doc.Write(Fs);
Fs.Close();
}
引用了NOPI 纸张方向默认是纵向的,请问怎么设置成横向的,就像图片里一样
参考下免费版Spire.Doc的设置
Document document = new Document();
document.LoadFromFile(@"No_Peelie.docx");
Section section = document.Sections[0];
//设置页面方向
section.PageSetup.Orientation = PageOrientation.Landscape;
document.SaveToFile(@"No_Peelie.docx", FileFormat.Docx2013);