国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

使用aspose.word 第三方的插件實(shí)現(xiàn)導(dǎo)出word

2020-01-24 01:47:57
字體:
供稿:網(wǎng)友

使用aspose.word 第三方的插件實(shí)現(xiàn)服務(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)用模塊對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 頁面設(shè)置,設(shè)置頁面為橫向布局,設(shè)置紙張類型為A4紙或通過頁面的寬度設(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; //五號        #endregion         List<double> widthList = new List<double>();        double remarkWidth = 0;        for (int k = 0; k < 18; k++)        {          builder.MoveToCell(0, 1, k, 0); //移動單元格          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è)置--------- 開頭          doc.Range.Bookmarks["tbdw"].Text = this.lblcom.Text;           builder.MoveToBookmark("pxtx");    //開始添加值          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();// 添加一個單元格                        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;//垂直居中對齊              builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//水平居中對齊              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();// 添加一個單元格                    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;//垂直居中對齊          builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//水平居中對齊          builder.Write("備注:");          builder.EndRow();          #endregion           #region 繪制表格以及設(shè)置--------- 結(jié)尾          builder.EndTable();          doc.Range.Bookmarks["pxtx"].Text = "";  // 清掉標(biāo)示           #endregion           #region 計劃編制和審批人          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,并打開        #endregion

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 崇明县| 沙洋县| 郸城县| 泌阳县| 石河子市| 措美县| 阆中市| 井冈山市| 琼结县| 墨江| 金川县| 牟定县| 汉寿县| 镇远县| 安图县| 浑源县| 张家口市| 湘阴县| 左权县| 东明县| 济南市| 廊坊市| 枣强县| 金昌市| 马边| 朝阳区| 日土县| 买车| 章丘市| 馆陶县| 双流县| 珠海市| 上虞市| 剑川县| 安阳县| 宜宾市| 韶关市| 太仆寺旗| 容城县| 陇南市| 陇南市|