使用aspose.word 第三方的插件實(shí)現(xiàn)導(dǎo)出word
使用aspose.word 第三方的插件實(shí)現(xiàn)服務(wù)器端無(wú)需安裝office組件導(dǎo)出word的功能
#region 生成的excel文件命名和確保文件的唯一性
Random rd = new Random();
DateTime dtime = DateTime.Now;
string Filename = "培訓(xùn)需求表" + dtime.Year.ToString() + dtime.Month.ToString() + dtime.Day.ToString() + dtime.Hour.ToString() + dtime.Minute.ToString() + dtime.Second.ToString() + Convert.ToString(rd.Next(99) * 97 + 100) + ".doc";
#endregion
#region 定義變量
//建立Document物件,調(diào)用模塊對(duì)word字體和table格式設(shè)置
string serverpath = Constants.GetAppSettingValue("LocalLogicPath") + Constants.GetAppSettingValue("LocalTemplate") + "px_xqjh_tx.doc";
Document doc = new Document(serverpath);
//建立DocumentBuilder物件
DocumentBuilder builder = new DocumentBuilder(doc);
#endregion
#region 頁(yè)面設(shè)置,設(shè)置頁(yè)面為橫向布局,設(shè)置紙張類型為A4紙或通過(guò)頁(yè)面的寬度設(shè)置
//設(shè)置紙張布局
builder.PageSetup.PaperSize = PaperSize.A4;
//builder.PageSetup.Orientation = Aspose.Words.Orientation.Landscape;
#endregion
#region 設(shè)置word全局的字體樣式和字體大小
builder.RowFormat.Borders.LineStyle = LineStyle.Thick;
builder.RowFormat.HeightRule = HeightRule.Auto;
builder.RowFormat.Alignment = RowAlignment.Center;
//builder.Font.Name = "仿宋-GB2312";
builder.Font.Name = "宋體";
builder.Font.Size = 10.5; //五號(hào)
#endregion
List<double> widthList = new List<double>();
double remarkWidth = 0;
for (int k = 0; k < 18; k++)
{
builder.MoveToCell(0, 1, k, 0); //移動(dòng)單元格
double width = builder.CellFormat.Width;//獲取單元格寬度
widthList.Add(width);
remarkWidth += width;
//Universal.ExceptionLog(k.ToString(), width.ToString());
}
DataTable dtable = GetQuestionList();
if (dtable != null && dtable.Rows.Count > 0)
{
#region 繪制表格以及設(shè)置--------- 開(kāi)頭
doc.Range.Bookmarks["tbdw"].Text = this.lblcom.Text;
builder.MoveToBookmark("pxtx"); //開(kāi)始添加值
Aspose.Words.Tables.Table table = builder.StartTable();
builder.RowFormat.HeadingFormat = true;
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
#endregion
#region 數(shù)據(jù)集
for (int i = 0; i < dtable.Rows.Count; i++)
{
for (int j = 0; j < dtable.Columns.Count - 3; j++)
{
#region 列
builder.InsertCell();// 添加一個(gè)單元格
builder.CellFormat.Borders.LineStyle = LineStyle.Single;
builder.CellFormat.Borders.Color = System.Drawing.Color.Black;
builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb(255, 255, 255);
builder.CellFormat.Width = widthList[j];
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Top;//垂直居中對(duì)齊
builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//水平居中對(duì)齊
builder.Write(dtable.Rows[i][j].ToString().Trim());
//Universal.ExceptionLog((i + 1).ToString() + "*" + (j + 1).ToString(), dtable.Rows[i][j].ToString().Trim());
#endregion
}
builder.EndRow();
}
#endregion
#region 備注列
builder.InsertCell();// 添加一個(gè)單元格
builder.CellFormat.Borders.LineStyle = LineStyle.Single;
builder.CellFormat.Borders.Color = System.Drawing.Color.Black;
builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb(255, 255, 255);
builder.CellFormat.Width = remarkWidth;
builder.RowFormat.Height = 50;
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Top;//垂直居中對(duì)齊
builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//水平居中對(duì)齊
builder.Write("備注:");
builder.EndRow();
#endregion
#region 繪制表格以及設(shè)置--------- 結(jié)尾
builder.EndTable();
doc.Range.Bookmarks["pxtx"].Text = ""; // 清掉標(biāo)示
#endregion
#region 計(jì)劃編制和審批人
doc.Range.Bookmarks["writername"].Text = dtable.Rows[0]["reg_staff_name"].ToString();
doc.Range.Bookmarks["checkname"].Text = dtable.Rows[0]["check_man_name"].ToString();
#endregion
}
dtable.Dispose();
#region 保存數(shù)據(jù).
doc.Save(Filename, SaveFormat.Doc, SaveType.OpenInWord, Response); //保存為doc,并打開(kāi)
#endregion
- asp.net下用Aspose.Words for .NET動(dòng)態(tài)生成word文檔中的數(shù)據(jù)表格的方法
- asp.net下用Aspose.Words for .NET動(dòng)態(tài)生成word文檔中的圖片或水印的方法
- 解決用Aspose.Words,在word文檔中創(chuàng)建表格的實(shí)現(xiàn)方法
- .net使用Aspose.Words進(jìn)行Word替換操作的實(shí)現(xiàn)代碼
- 利用Aspose.Word控件實(shí)現(xiàn)Word文檔的操作
- C# 利用Aspose.Words.dll將 Word 轉(zhuǎn)成PDF
- 使用Aspose.Cells組件生成Excel文件實(shí)例
- C#使用Aspose.Cells控件讀取Excel
相關(guān)文章
Unity3D使用UGUI開(kāi)發(fā)原生虛擬搖桿
這篇文章主要為大家詳細(xì)介紹了Unity3D使用UGUI開(kāi)發(fā)原生虛擬搖桿,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-04-04
C# WinForm自動(dòng)更新程序之文件上傳操作詳解
這篇文章主要為大家詳細(xì)介紹了C# WinForm自動(dòng)更新程序中文件上傳操作,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,感興趣的小伙伴可以了解一下2022-10-10
C# 中 System.Index 結(jié)構(gòu)體和 Hat 運(yùn)算符(^)的使用示例
這篇文章主要介紹了C# 中 System.Index 結(jié)構(gòu)體和 Hat 運(yùn)算符(^)的使用示例,幫助大家更好的理解和使用C#,感興趣的朋友可以了解下2020-09-09
C# MJPEG 客戶端簡(jiǎn)單實(shí)現(xiàn)方法
這篇文章主要介紹了C# MJPEG 客戶端簡(jiǎn)單實(shí)現(xiàn)的方法,幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下2021-03-03
C#實(shí)現(xiàn)觀察者模式(Observer?Pattern)的兩種方式
這篇文章介紹了C#實(shí)現(xiàn)觀察者模式(Observer?Pattern)的兩種方式,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-08-08
C#基于Mongo的官方驅(qū)動(dòng)手?jǐn)]一個(gè)Super簡(jiǎn)易版MongoDB-ORM框架
本文給大家分享C#基于Mongo的官方驅(qū)動(dòng)手?jǐn)]一個(gè)簡(jiǎn)易版MongoDB-ORM框架,是一款屬于super簡(jiǎn)易版的,通過(guò)圖文的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2021-05-05

