Example #1
0
        /// <summary>
        /// 插入的表格中不包括dt的表头的基方法
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="dt"></param>
        /// <param name="rowHeightList">行高</param>
        /// <param name="colWidthList">列宽</param>
        /// <param name="mcell">合并</param>
        /// <returns></returns>
        public static Table WriteTableEx(Aspose.Words.DocumentBuilder builder, DataTable dt, List <double> rowHeightList, List <double> colWidthList, IList <MCell> mcell)
        {
            ;
            builder.ParagraphFormat.StyleIdentifier = Aspose.Words.StyleIdentifier.BodyText;
            var table = builder.StartTable();

            //table.LeftIndent = 20.0;
            builder.RowFormat.Height             = 25.0;
            builder.RowFormat.HeightRule         = HeightRule.Auto;// HeightRule.AtLeast
            builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;

            builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
            builder.Font.Size = 10.5;
            builder.Font.Name = "宋体";
            // builder.CellFormat.Width = 200;
            builder.CellFormat.Shading.BackgroundPatternColor = Color.White;
            builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
            var cellM = mcell.FirstOrDefault(e => e.IsColumn);

            for (int j = 0; j < dt.Rows.Count; j++)
            {
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    builder.CellFormat.Width = colWidthList[i];
                    builder.InsertCell();
                    builder.Write(dt.Rows[j][i].ToString().Trim());
                }
                builder.EndRow();
            }
            builder.EndTable();
            return(table);
        }
Example #2
0
        public static void AppendCategoryText(string filepath, string categoryName)
        {
            try
            {
                Aspose.Words.DocumentBuilder db = new Aspose.Words.DocumentBuilder(destdoc);
                db.MoveToDocumentEnd();

                string categoryText = "<div style='font-weight:bold;text-decoration:underline;width:800px;text-align: center;'>Category " + categoryName + "</div>";
                if (categoryName == "F")
                {
                    categoryText = "<div style='font-weight:bold;text-decoration:underline;width:800px;text-align: center;'>Category " + categoryName + " [Independent Unit]</div>";
                }

                db.InsertBreak(BreakType.PageBreak);
                db.InsertHtml(categoryText, false);
            }
            catch (Exception ex)
            {
                ex = new Exception("Report -> AppendCategoryText: \r\n\r\n", ex);
                LogManager.WriteErrorLog(ex);
                destdoc = null;
                throw ex;
            }
            GC.Collect();
        }
Example #3
0
 public Document SetWord(Document doc, DataTable dt)
 {
     //要取得目标的DataTable
     Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
     //List<double> widthList = new List<double>();
     //for (int i = 0; i < dt.Columns.Count; i++)
     //{
     //    builder.MoveToCell(0, 0, i, 0); //移动单元格
     //    double width = builder.CellFormat.Width;//获取单元格宽度
     //    widthList.Add(width);
     //}
     builder.MoveToBookmark("table");        //开始添加值
     for (var i = 0; i < dt.Rows.Count; i++)
     {
         for (var j = 0; j < dt.Columns.Count; j++)
         {
             builder.InsertCell();// 添加一个单元格
             builder.CellFormat.Borders.LineStyle = LineStyle.Single;
             builder.CellFormat.Borders.Color     = System.Drawing.Color.Black;
             //builder.CellFormat.Width = width[j];
             builder.CellFormat.VerticalMerge     = Aspose.Words.Tables.CellMerge.None;
             builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center; //垂直居中对齐
             builder.ParagraphFormat.Alignment    = ParagraphAlignment.Center;                        //水平居中对齐
             builder.Write(dt.Rows[i][j].ToString());
         }
         builder.EndRow();
     }
     doc.Range.Bookmarks["table"].Text = "";    // 清掉标示
     return(doc);
 }
Example #4
0
        /// <summary>
        /// 带签章的pdf保存
        /// </summary>
        /// <param name="fileTemp">doc模板</param>
        /// <param name="signatureImag">签章图片</param>
        /// <param name="outFilePath">输出路径</param>
        public void SavAsPdf(string fileTemp, string signatureImag, string outFilePath)
        {
            oDoc = new Document(fileTemp);
            Bookmark bKGetDate = oDoc.Range.Bookmarks["GetDate"];

            if (bKGetDate != null)
            {
                oDoc.Range.Bookmarks["GetDate"].Text = DateTime.Now.ToString("yyyy年MM月dd日");
            }
            Bookmark bKsignatureImage = oDoc.Range.Bookmarks["signatureImage"];

            if (bKsignatureImage != null)
            {
                Aspose.Words.DocumentBuilder dbuilder = new Aspose.Words.DocumentBuilder(oDoc);
                dbuilder.MoveToBookmark("signatureImage");
                dbuilder.InsertImage(signatureImag, Aspose.Words.Drawing.RelativeHorizontalPosition.Character, -130,
                                     Aspose.Words.Drawing.RelativeVerticalPosition.BottomMargin, 0, 120, 120, Aspose.Words.Drawing.WrapType.None);
            }
            int pageCount = oDoc.PageCount;

            if (pageCount > 1 && bKsignatureImage != null)
            {
                SealPath = signatureImag;
                AddPageSeal(outFilePath, pageCount);
            }
            else//直接生成pdf
            {
                oDoc.Save(outFilePath, SaveFormat.Pdf);
            }
        }
        public override void exportarRolAWord(Aspose.Words.DocumentBuilder docBuilder, Viewer.Application.Dto.DocumentoInstanciaXbrlDto instancia, Dto.IndiceReporteDTO rolAExportar, Dto.ReporteXBRLDTO estructuraReporte)
        {
            docBuilder.CurrentSection.PageSetup.Orientation = Orientation.Landscape;
            docBuilder.CurrentSection.PageSetup.PaperSize   = PaperSize.Legal;
            docBuilder.CurrentSection.PageSetup.LeftMargin  = 10;
            docBuilder.CurrentSection.PageSetup.RightMargin = 10;


            escribirEncabezado(docBuilder, instancia, estructuraReporte, true);


            imprimirTituloRol(docBuilder, rolAExportar);


            Table tablaDesglose = docBuilder.StartTable();

            docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
            establecerFuenteTituloCampo(docBuilder);
            docBuilder.Font.Size = TamanioLetraReporteDesglose;

            docBuilder.ParagraphFormat.SpaceAfter  = 0;
            docBuilder.ParagraphFormat.SpaceBefore = 2;

            var idioma = estructuraReporte.Lenguaje;

            ImprimirTitulosGrupoPasivo(ImportadorExportadorRol815100Bmv2014._elementosPrimariosBancarios, docBuilder, instancia, idioma);

            ImprimirGrupoTipoPasivo(ImportadorExportadorRol815100Bmv2014._miembrosTipoPasivo[0],
                                    ImportadorExportadorRol815100Bmv2014._elementosPrimariosBancarios, docBuilder, instancia, idioma, estructuraReporte);

            ImprimirGrupoTipoPasivo(ImportadorExportadorRol815100Bmv2014._miembrosTipoPasivo[1],
                                    ImportadorExportadorRol815100Bmv2014._elementosPrimariosBancarios, docBuilder, instancia, idioma, estructuraReporte);

            ImprimirTitulosGrupoPasivo(ImportadorExportadorRol815100Bmv2014._elementosPrimariosBursatiles, docBuilder, instancia, idioma);

            ImprimirGrupoTipoPasivo(ImportadorExportadorRol815100Bmv2014._miembrosTipoPasivo[2],
                                    ImportadorExportadorRol815100Bmv2014._elementosPrimariosBursatiles, docBuilder, instancia, idioma, estructuraReporte);

            ImprimirGrupoTipoPasivo(ImportadorExportadorRol815100Bmv2014._miembrosTipoPasivo[3],
                                    ImportadorExportadorRol815100Bmv2014._elementosPrimariosBursatiles, docBuilder, instancia, idioma, estructuraReporte);

            ImprimirGrupoTipoPasivo(ImportadorExportadorRol815100Bmv2014._miembrosTipoPasivo[4],
                                    ImportadorExportadorRol815100Bmv2014._elementosPrimariosBursatiles, docBuilder, instancia, idioma, estructuraReporte);

            ImprimirTitulosGrupoPasivo(ImportadorExportadorRol815100Bmv2014._elementosPrimariosOtros, docBuilder, instancia, idioma);

            ImprimirGrupoTipoPasivo(ImportadorExportadorRol815100Bmv2014._miembrosTipoPasivo[5],
                                    ImportadorExportadorRol815100Bmv2014._elementosPrimariosOtros, docBuilder, instancia, idioma, estructuraReporte);

            ImprimirGrupoTipoPasivo(ImportadorExportadorRol815100Bmv2014._miembrosTipoPasivo[6],
                                    ImportadorExportadorRol815100Bmv2014._elementosPrimariosOtros, docBuilder, instancia, idioma, estructuraReporte);

            ImprimirGrupoTipoPasivo(ImportadorExportadorRol815100Bmv2014._miembrosTipoPasivo[7],
                                    ImportadorExportadorRol815100Bmv2014._elementosPrimariosGranTotal, docBuilder, instancia, idioma, estructuraReporte);


            establecerBordesGrisesTabla(tablaDesglose);
            docBuilder.EndTable();
        }
Example #6
0
        private void ReportWord()
        {
            try
            {
                string templateFile = Server.MapPath("~/Temp/WordTemplate.doc");
                string saveDocFile  = Server.MapPath("~/Word/" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".doc");
                Aspose.Words.Document        doc     = new Aspose.Words.Document(templateFile);
                Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
                DataTable nameList = new DataTable();

                nameList.Columns.Add("编号", typeof(string));
                nameList.Columns.Add("姓名", typeof(string));
                nameList.Columns.Add("时间", typeof(string));
                DataRow row = null;
                for (int i = 0; i < 50; i++)
                {
                    row       = nameList.NewRow();
                    row["编号"] = i.ToString().PadLeft(4, '0');
                    row["姓名"] = "伍华聪 " + i.ToString();
                    row["时间"] = DateTime.Now.ToString();
                    nameList.Rows.Add(row);
                }

                List <double> widthList = new List <double>();
                for (int i = 0; i < nameList.Columns.Count; i++)
                {
                    builder.MoveToCell(0, 0, i, 0);          //移动单元格
                    double width = builder.CellFormat.Width; //获取单元格宽度
                    widthList.Add(width);
                }

                builder.MoveToBookmark("table");        //开始添加值
                for (var i = 0; i < nameList.Rows.Count; i++)
                {
                    for (var j = 0; j < nameList.Columns.Count; j++)
                    {
                        builder.InsertCell();// 添加一个单元格
                        builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Color     = System.Drawing.Color.Black;
                        builder.CellFormat.Width             = widthList[j];
                        builder.CellFormat.VerticalMerge     = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; //垂直居中对齐
                        builder.ParagraphFormat.Alignment    = ParagraphAlignment.Center;    //水平居中对齐
                        builder.Write(nameList.Rows[i][j].ToString());
                    }

                    builder.EndRow();
                }
                doc.Save(saveDocFile);
                doc.Range.Bookmarks["table"].Text = "";    // 清掉标示
                //doc.Save(saveDocFile);

                System.Diagnostics.Process.Start(saveDocFile);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #7
0
 public static void WriteHead3(Aspose.Words.DocumentBuilder builder, string text)
 {
     builder.ParagraphFormat.Alignment       = ParagraphAlignment.Left;
     builder.ParagraphFormat.StyleIdentifier = Aspose.Words.StyleIdentifier.Heading3;
     builder.Write(text);
     // builder.AAWriteText("一、分组学校名单", 16, true);
     builder.InsertBreak(BreakType.ParagraphBreak);
 }
Example #8
0
        /// <summary>
        /// 写表格 列宽 行高
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="dt"></param>
        /// <param name="rowHeightList"></param>
        /// <param name="colWidthList"></param>
        public static Table WriteTable(Aspose.Words.DocumentBuilder builder, DataTable dt, int startRow = 1, params int[] colIndexs)
        {
            var tableW = ConfigurationManager.AppSettings["tableWidth"].ToInt();

            builder.ParagraphFormat.StyleIdentifier = Aspose.Words.StyleIdentifier.BodyText;
            var table = builder.StartTable();

            //table.LeftIndent = 20.0;
            builder.RowFormat.Height = 25.0;

            builder.RowFormat.HeightRule = HeightRule.Auto;// HeightRule.AtLeast
            builder.CellFormat.Shading.BackgroundPatternColor = Color.FromArgb(191, 191, 191);
            builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
            builder.ParagraphFormat.Alignment    = ParagraphAlignment.Center;
            builder.Font.Size = 10.5;
            builder.Font.Name = "宋体";
            if (colIndexs.Length == 0)
            {
                var lst = new List <int>();
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    lst.Add(i);
                }
                colIndexs = lst.ToArray();
            }
            //表宽除以列数=列宽
            var cellW = ((1.00 * tableW) / colIndexs.Length).Round(0);

            builder.CellFormat.Width       = cellW;
            builder.CellFormat.LeftPadding = 0;

            foreach (var i in colIndexs)
            {
                var cell = builder.InsertCell();

                builder.Write(dt.Columns[i].ColumnName);
            }

            builder.EndRow();
            builder.CellFormat.Shading.BackgroundPatternColor = Color.White;
            builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
            builder.ParagraphFormat.Alignment    = ParagraphAlignment.Center;

            for (int j = startRow; j < dt.Rows.Count; j++)
            {
                foreach (var i in colIndexs)
                {
                    builder.InsertCell();
                    builder.Write(dt.Rows[j][i].ToString().Trim());
                }

                builder.EndRow();
            }
            builder.EndTable();

            //MergeCell(builder, table, mcell);
            return(table);
        }
Example #9
0
        /// <summary>
        /// 插入的表格中不包括dt的表头,builder、dt、列宽3个参数
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="dt"></param>
        /// <param name="colWidthList"></param>
        /// <param name="rHeignt"></param>
        /// <returns></returns>
        public static Table WriteTableEx(Aspose.Words.DocumentBuilder builder, DataTable dt, List <double> colWidthList, double rHeignt = 25)
        {
            var hList = new List <double>()
            {
                rHeignt
            };

            return(WriteTableEx(builder, dt, hList, colWidthList, new List <MCell>()));
        }
Example #10
0
        /// <summary>
        /// 写表格下面图片
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="path"></param>
        public static void WriteImage(Aspose.Words.DocumentBuilder builder, string path, double width, double height)
        {
            string image = path;

            if (File.Exists(path))
            {
                builder.AAInsertImage(image, width, height, 0, 0);
                builder.InsertBreak(BreakType.ParagraphBreak);
            }
        }
Example #11
0
 public void ClearFormattingEx()
 {
     //ExStart
     //ExFor:ClearFormatting
     //ExId:ClearFormattingEx
     //ExSummary:Shows how to use ClearFormatting.
     Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Document.doc");
     Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
     builder.Font.Border.ClearFormatting();
     //ExEnd
 }
Example #12
0
        /// <summary>
        /// 构造函数初始化,初始化许可、保存路径、临时文档(模板)、
        /// </summary>
        /// <param name="tempdoc"></param>
        public BaseWord(string tempdoc = "附件2-收文登记--带书签")
        {
            //this.Init();
            string fileName = System.DateTime.Now.ToString("yyyyMMddHHmmss") + ".docx";

            this.SavePath     = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);
            this.WordTemplate = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "JCBG", "WordModel", tempdoc + ".docx");

            this.doc     = new Aspose.Words.Document(this.WordTemplate);
            this.builder = new Aspose.Words.DocumentBuilder(doc);
        }
Example #13
0
 public WordHelper()
 {
     if (wDoc == null)
     {
         wDoc = new AW.Document();
     }
     if (wDoc != null && wDocBuilder == null)
     {
         wDocBuilder = new AW.DocumentBuilder(wDoc);
     }
 }
Example #14
0
 public void ClearFormattingEx()
 {
     //ExStart
     //ExFor:ClearFormatting
     //ExId:ClearFormattingEx
     //ExSummary:Shows how to use ClearFormatting.
     Aspose.Words.Document        doc     = new Aspose.Words.Document(MyDir + "Document.doc");
     Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder();
     builder.Font.Border.ClearFormatting();
     //ExEnd
 }
Example #15
0
 public WordHelper(Stream stream, AW.LoadOptions loadOptions = null)
 {
     if (wDoc == null)
     {
         wDoc = loadOptions == null ? new AW.Document(stream) : new AW.Document(stream, loadOptions);
     }
     if (wDoc != null && wDocBuilder == null)
     {
         wDocBuilder = new AW.DocumentBuilder(wDoc);
     }
 }
Example #16
0
 public WordHelper(string fileName, AW.LoadOptions loadOptions = null)
 {
     if (wDoc == null)
     {
         wDoc = loadOptions == null ? new AW.Document(fileName) : new AW.Document(fileName, loadOptions);
     }
     if (wDoc != null && wDocBuilder == null)
     {
         wDocBuilder = new AW.DocumentBuilder(wDoc);
     }
 }
Example #17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="templateName">带后缀.docx</param>
        /// <param name="downloadFileName">不带后缀</param>
        public WordTemplateExport(string templateName, string downloadFileName)//, List<Dictionary<string, object>> rows)
        {
            var sourcePath = Path.Combine(PFDataHelper.BaseDirectory, "ExportTemplate", "Word", templateName);
            var targetPath = PFDataHelper.BaseDirectory + "word.doc";

            //Aspose.Words.License l = new Aspose.Words.License();
            //l.SetLicense(Path.Combine(HttpRuntime.AppDomainAppPath, "lib/Aid/WordLicense.lic"));
            document = new Aspose.Words.Document(sourcePath);
            Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(document);

            _downloadFileName = downloadFileName;
        }
Example #18
0
 /// <summary>
 /// 写表头标注
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="text"></param>
 public static void WriteTableMark(Aspose.Words.DocumentBuilder builder, string text)
 {
     if (text == null)
     {
         text = "";
     }
     builder.ParagraphFormat.StyleIdentifier = Aspose.Words.StyleIdentifier.BodyText;
     builder.ParagraphFormat.Alignment       = ParagraphAlignment.Center;
     builder.Write(text);
     // builder.AAWriteText("一、分组学校名单", 16, true);
     builder.InsertBreak(BreakType.ParagraphBreak);
 }
Example #19
0
        /// <summary>
        /// 处理逻辑
        /// </summary>
        public void ProcessAction()
        {
            Aspose.Words.Document        doc     = new Aspose.Words.Document(TemplateFile);
            Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);

            BookMarkTestMethod(doc, builder);

            InsertDocumentTest(doc, builder);

            doc.Save(SaveDocFile);
            System.Diagnostics.Process.Start(SaveDocFile);
        }
Example #20
0
        public static void Create(string templateFile, string saveFile, Dictionary <string, string> Datas)
        {
            Document        doc     = new Aspose.Words.Document(templateFile);
            DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);

            foreach (Bookmark bookmark in doc.Range.Bookmarks)
            {
                bookmark.Text = Datas[bookmark.Name];
            }

            doc.Save(saveFile, Aspose.Words.SaveFormat.Docx);
        }
Example #21
0
        public static Table WriteHeadGroupTable(Aspose.Words.DocumentBuilder builder, DataTable dt, IList <MCell> mcell, int StartRow, IList <ColorCell> listCell)
        {
            builder.ParagraphFormat.StyleIdentifier = Aspose.Words.StyleIdentifier.BodyText;
            var table = builder.StartTable();

            //table.LeftIndent = 20.0;
            builder.RowFormat.Height     = 25.0;
            builder.RowFormat.HeightRule = HeightRule.Auto;// HeightRule.AtLeast
            builder.CellFormat.Shading.BackgroundPatternColor = Color.FromArgb(191, 191, 191);
            builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;

            builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
            builder.Font.Size = 10.5;
            builder.Font.Name = "宋体";
            for (int i = 0; i < StartRow; i++)
            {
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    builder.InsertCell();
                    builder.Write(dt.Rows[i][j].ToString());
                }
                builder.EndRow();
            }


            builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
            var cellM = mcell.FirstOrDefault(e => e.IsColumn);

            for (int j = StartRow; j < dt.Rows.Count; j++)
            {
                builder.CellFormat.Shading.BackgroundPatternColor = Color.White;
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    var cell     = builder.InsertCell();
                    var rowColor = listCell.FirstOrDefault(e => e.ColumnIndex == i && e.RowIndex == j);
                    if (rowColor != null)
                    {
                        cell.CellFormat.Shading.BackgroundPatternColor = Color.Yellow;
                    }
                    else
                    {
                        builder.CellFormat.Shading.BackgroundPatternColor = Color.White;
                    }
                    builder.Write(dt.Rows[j][i].ToString());
                }
                builder.EndRow();
            }
            builder.EndTable();
            MergeCell(builder, table, mcell);
            return(table);
        }
Example #22
0
        public void EqualsEx()
        {
            //ExStart
            //ExFor:Equals
            //ExId:EqualsEx
            //ExSummary:Shows how to use Equals.
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Document.doc");
            Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
            Aspose.Words.Border border1 = builder.Font.Border;
            Aspose.Words.Border border2 = builder.Font.Border;

            Console.WriteLine(border1.Equals(border2));
            //ExEnd
        }
Example #23
0
        /// <summary>
        /// 写表格下面图片
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="path"></param>
        public static void WriteImage(Aspose.Words.DocumentBuilder builder, string path)
        {
            string image = path;

            if (!string.IsNullOrEmpty(path) && File.Exists(path))
            {
                builder.ParagraphFormat.StyleIdentifier = Aspose.Words.StyleIdentifier.BodyText;
                builder.ParagraphFormat.Alignment       = ParagraphAlignment.Center;
                var w = ConfigurationManager.AppSettings["chartWidth1"].ToInt();
                var h = ConfigurationManager.AppSettings["chartHeight1"].ToInt();
                builder.AAInsertImage(image, w, h, 0, 0);
                builder.InsertBreak(BreakType.ParagraphBreak);
            }
        }
Example #24
0
        private void btnGenerateDoc_Click(object sender, EventArgs e)
        {
            string fileName    = string.Format("数据库设计文档.doc");
            string saveDocFile = FileDialogHelper.SaveWord(fileName, "C:\\");

            if (!string.IsNullOrEmpty(saveDocFile))
            {
                try
                {
                    #region 准备工作
                    Aspose.Words.Document doc = new Aspose.Words.Document();
                    doc.BuiltInDocumentProperties.Title         = "数据库设计说明书";
                    doc.BuiltInDocumentProperties.Keywords      = "数据库设计说明书";
                    doc.BuiltInDocumentProperties.CreatedTime   = DateTimeHelper.GetServerDateTime2();
                    doc.BuiltInDocumentProperties.LastSavedTime = DateTimeHelper.GetServerDateTime2();

                    Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
                    builder.PageSetup.PaperSize   = PaperSize.A4;
                    builder.PageSetup.Orientation = Aspose.Words.Orientation.Portrait;
                    builder.InsertParagraph();

                    Dictionary <string, string> tableList = new Dictionary <string, string>();
                    tableList.Add("TB_DictType", "数据字典类型基础表");
                    tableList.Add("TB_DictData", "数据字典项目基础表");
                    tableList.Add("TB_LoginLog", "用户登陆日志表");

                    int i = 1;
                    foreach (string key in tableList.Keys)
                    {
                        string description = string.Format("{0}({1})", key, tableList[key]);
                        GenerateTableData(doc, builder, i++, description);
                    }

                    #endregion

                    doc.Save(saveDocFile, SaveFormat.Doc);
                    if (MessageDxUtil.ShowYesNoAndTips("保存成功,是否打开文件?") == System.Windows.Forms.DialogResult.Yes)
                    {
                        System.Diagnostics.Process.Start(saveDocFile);
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, ex, typeof(FrmAsposeWords));
                    MessageDxUtil.ShowError(ex.Message);
                    return;
                }
            }
        }
Example #25
0
        private void AbsenceNotification_MailMerge_MergeField(object sender, Aspose.Words.Reporting.MergeFieldEventArgs e)
        {
            if (e.FieldName == "懲戒明細")
            {
                List <string> eachStudentDisciplineDetail = (List <string>)e.FieldValue;

                Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(e.Document);

                builder.MoveToField(e.Field, false);
                builder.StartTable();
                builder.CellFormat.ClearFormatting();
                builder.CellFormat.Borders.ClearFormatting();
                builder.CellFormat.VerticalAlignment = Aspose.Words.CellVerticalAlignment.Center;
                builder.CellFormat.LeftPadding       = 3.0;
                builder.RowFormat.LeftIndent         = 0.0;
                builder.RowFormat.Height             = 15.0;

                int rowNumber = 6;

                if (eachStudentDisciplineDetail.Count > rowNumber * 2)
                {
                    rowNumber += (eachStudentDisciplineDetail.Count - (rowNumber * 2)) / 2;
                    rowNumber += (eachStudentDisciplineDetail.Count - (rowNumber * 2)) % 2;
                }

                for (int j = 0; j < rowNumber; j++)
                {
                    builder.InsertCell();
                    builder.CellFormat.Borders.Right.LineStyle = Aspose.Words.LineStyle.Single;
                    builder.CellFormat.Borders.Right.Color     = Color.Black;
                    if (j < eachStudentDisciplineDetail.Count)
                    {
                        builder.Write(eachStudentDisciplineDetail[j]);
                    }
                    builder.InsertCell();
                    if (j + rowNumber < eachStudentDisciplineDetail.Count)
                    {
                        builder.Write(eachStudentDisciplineDetail[j + rowNumber]);
                    }
                    builder.EndRow();
                }

                builder.EndTable();

                e.Text = string.Empty;
            }
        }
Example #26
0
        public static void AppendJuryTabularDetail(EnumerableRowCollection <DataRow> dataRows, string filepath, string productName)
        {
            try
            {
                Aspose.Words.DocumentBuilder db = new Aspose.Words.DocumentBuilder(destdoc);
                db.MoveToDocumentEnd();

                StringBuilder sb = new StringBuilder();
                sb.Append("<html><head><style>table, th, td {border: 1px solid black;border-collapse: collapse;text-align:center;font-size:15px;}</style></head><body>");
                sb.Append("<table cellpadding='2' style='color:black;width:100%'><tbody>");
                sb.AppendFormat("<tr><td style='font-weight:bold;font-size:17px;' colspan='3'>{0}</td></tr>", productName);
                sb.AppendFormat("<tr><td style='font-weight:bold;'>Sr. No.</td><td style='font-weight:bold;'>Applicant</td><td style='font-weight:bold;'>Total Score</td></tr>");

                var count = 1;
                for (var index = 65; index <= 71; index++)
                {
                    Char alphabet = (Char)index;
                    var  data     = dataRows.Where(dr => dr.Field <string>("ClassificationName") == alphabet.ToString()).ToList();
                    if (data != null && data.Count > 0)
                    {
                        sb.AppendFormat("<tr><td colspan='3'>Turnover Classification {0}</td></tr>", alphabet);
                        for (var j = 0; j < data.Count(); j++)
                        {
                            sb.AppendFormat("<tr><td>{0}</td><td style='font-weight:bold;'>{1}</td><td style='font-weight:bold;'>{2}</td></tr>", count, data[j]["OrganisationName"], data[j]["Score"]);
                            count++;
                        }
                    }
                }

                sb.AppendLine("</tbody></table></body></html>");

                db.InsertBreak(BreakType.PageBreak);
                db.InsertHtml(sb.ToString(), false);
            }
            catch (Exception ex)
            {
                ex = new Exception("Report -> AppendJuryTabularDetail: \r\n\r\n", ex);
                LogManager.WriteErrorLog(ex);
                destdoc = null;
                throw ex;
            }


            GC.Collect();
        }
        //生成考核单word
        public FileResult GetAppraiseBill(int feedBackID)
        {
            string fileName = Server.MapPath(@"/template/供应商日常考核记录单.doc");

            Aspose.Words.Document        doc     = new Aspose.Words.Document(fileName);
            Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);

            var info = db.MaterialQualityFeedback.Find(feedBackID);

            builder.MoveToBookmark("SupplierName");
            builder.Write(info.SupplierName);

            var lastNum = db.MaterialQualityFeedback.Max(m => m.AppraiseBillNum);

            lastNum = lastNum == 0 ? 1 : lastNum + 1;
            var    appraiseBillNum = "000" + (info.AppraiseBillNum == 0 ? lastNum : info.AppraiseBillNum).ToString();
            var    fileNameWord    = "供应商日常考核记录单--" + appraiseBillNum.Substring(appraiseBillNum.Length - 4, 4);
            string fileToSave      = System.IO.Path.Combine(Server.MapPath("/"), "FileOutput/" + fileNameWord + ".doc");

            if (System.IO.File.Exists(fileToSave))
            {
                System.IO.File.Delete(fileToSave);
            }
            doc.Save(fileToSave, SaveFormat.Doc);

            info.AppraiseBillNum       = info.AppraiseBillNum == 0 ? lastNum : info.AppraiseBillNum;
            info.AppraiseBillInputTime = DateTime.Now;
            info.AppraiseBillState     = "已生成";

            var person = App_Code.Commen.GetUserFromSession();
            var log    = new Models.Log();

            log.InputDateTime   = DateTime.Now;
            log.InputPersonID   = person.UserID;
            log.InputPersonName = person.UserName;
            log.LogType         = "物资质量反馈";
            log.LogContent      = "生成考核单";
            log.LogDataID       = info.ID;
            db.Log.Add(log);

            db.SaveChanges();
            return(File(fileToSave, "application/msword", fileNameWord + ".doc"));
        }
Example #28
0
 /// <summary>
 /// 合并
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="table"></param>
 /// <param name="mcell"></param>
 public static void MergeCell(Aspose.Words.DocumentBuilder builder, Table table, IList <MCell> mcell)
 {
     try
     {
         var rCount = table.Rows.Count;
         var cCount = table.Rows[0].Cells.Count;
         for (int i = 0; i < mcell.Count; i++)
         {
             var m = mcell[i];
             if (m.IsColumn)
             {
                 //某一列进行合并
                 //到达的行大于总行数、或者起始的某一列所以大于总列数
                 if (m.toR2C > rCount || cCount < m.C2RIndex)
                 {
                     continue;
                 }
                 //开始位置,起始行的开始列
                 Cell sCell = table.Rows[m.fromR2C].Cells[m.C2RIndex];
                 //结束位置,结束行的开始列
                 Cell eCell = table.Rows[m.toR2C].Cells[m.C2RIndex];
                 builder.AAMergeCells(sCell, eCell);
             }
             else
             {
                 //某一行进行合并
                 //到达列大于总列数或者起始的某一行大于总行数
                 if (m.toR2C > cCount || rCount < m.C2RIndex)
                 {
                     continue;
                 }
                 Cell sCell = table.Rows[m.C2RIndex].Cells[m.fromR2C];
                 Cell eCell = table.Rows[m.C2RIndex].Cells[m.toR2C];
                 builder.AAMergeCells(sCell, eCell);
             }
         }
     }
     catch (Exception ex)
     {
     }
 }
Example #29
0
        public static byte[] Txt2PDF(byte[] fileBuffer)
        {
            MemoryStream mystream = new MemoryStream(fileBuffer);

            var encoding = System.Text.Encoding.Default;

            if (fileBuffer.Length >= 2 && fileBuffer[0] >= 0xEF)
            {
                if (fileBuffer[0] == 0xEF && fileBuffer[1] == 0xBB)
                {
                    encoding = System.Text.Encoding.UTF8;
                }
                else if (fileBuffer[0] == 0xFE && fileBuffer[1] == 0xFF)
                {
                    encoding = System.Text.Encoding.BigEndianUnicode;
                }
                else if (fileBuffer[0] == 0xFF && fileBuffer[1] == 0xFE)
                {
                    encoding = System.Text.Encoding.Unicode;
                }
            }

            System.IO.TextReader tr = new StreamReader(mystream, encoding);
            var text = tr.ReadToEnd();

            var pdfStream = new MemoryStream();
            var doc       = new Aspose.Words.Document();

            Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
            Aspose.Words.Font            font    = builder.Font;
            font.Name = "宋体";
            builder.Write(text);
            // 转PDF
            doc.Save(pdfStream, Aspose.Words.SaveFormat.Pdf);
            var buffer = pdfStream.ToArray();

            pdfStream.Close();

            return(buffer);
        }
Example #30
0
 private void FormatReportWord()
 {
     try
     {
         string templateFile = Server.MapPath("~/Temp/FormartWordTemplate.doc");
         string saveDocFile  = Server.MapPath("~/Word/FormartWord" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".doc");
         Aspose.Words.Document        doc     = new Aspose.Words.Document(templateFile);
         Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
         builder.MoveToBookmark("模块名称");
         //builder.InsertFootnote(0,"这是一个模块");
         builder.Write("这是一个模块");
         builder.MoveToBookmark("操作动作");
         //builder.InsertFootnote(0,"这是一个模块");
         builder.Write("添加一个门店");
         doc.Save(saveDocFile);
         System.Diagnostics.Process.Start(saveDocFile);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #31
0
        //excel文档转换问题
        public static string GetPdfFromTxt(string soursefilepath, string scode)
        {
            //读取word文档
            try
            {
                using (StreamReader reader = new StreamReader(soursefilepath, Encoding.GetEncoding("gb2312")))
                {
                    string text = reader.ReadToEnd();
                    Aspose.Words.Document        doc     = new Aspose.Words.Document();
                    Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);

                    builder.Write(text);
                    string htmlName   = scode + ".pdf";//Path.GetFileNameWithoutExtension(physicalPath)
                    string outpdfpath = AppDomain.CurrentDomain.BaseDirectory + "pdfjs\\pdf\\" + htmlName;
                    doc.Save(outpdfpath, Aspose.Words.SaveFormat.Pdf);
                    return(outpdfpath);
                }
            }
            catch (Exception ex)
            {
                return("error!" + ex.Message);
            }
        }
Example #32
0
        public void temp()
        {
            // 產生合併欄位

            Aspose.Words.Document        doc     = new Document();
            Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
            builder.MoveToDocumentEnd();
            builder.Writeln();

            List <string> m1 = new List <string>();

            m1.Add("班級");
            m1.Add("座號");
            m1.Add("姓名");
            m1.Add("兄弟姊妹姓名");
            m1.Add("稱謂");
            m1.Add("生日");
            m1.Add("學校名稱");
            m1.Add("班級名稱");
            m1.Add("備註");

            builder.StartTable();

            for (int i = 1; i <= 12; i++)
            {
                foreach (string name in m1)
                {
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + name + i + " \\* MERGEFORMAT ", "«" + name + i + "»");
                }
                builder.EndRow();
            }
            builder.EndTable();

            doc.Save(Application.StartupPath + "\\test.doc", SaveFormat.Doc);
            System.Diagnostics.Process.Start(Application.StartupPath + "\\test.doc");
        }
Example #33
0
        public void ExpWD12(System.Data.DataTable dt)
        {
            #region //图片插入
            builder = new Aspose.Words.DocumentBuilder(doc);

            Shape shape = new Shape(doc, ShapeType.Image);
            shape.ImageData.SetImage("D:\\sw\\2010\\[Beautyleg]2010.06.18 No.414 Avy[73P]\\60.jpg");
            shape.Width = 850;
            shape.Height = 290;
            shape.HorizontalAlignment = HorizontalAlignment.Center; //靠右对齐
            if (doc.Range.Bookmarks["Z_IMG_24"] != null)
            {
                builder.MoveToBookmark("Z_IMG_24");
             //   builder.InsertImage("D:\\sw\\2010\\[Beautyleg]2010.06.18 No.414 Avy[73P]\\60.jpg", 550, 250);
                builder.InsertImage(dt.Rows[0][2].ToString(), 450, 200);
               // doc.Range.Bookmarks["Z_IMG_24"].Text = "";

            }
            if (doc.Range.Bookmarks["Z_IMG_41"] != null)
            {

                builder.MoveToBookmark("Z_IMG_41");
               // builder.InsertNode(shape);
             //   builder.InsertImage("D:\\sw\\2010\\[Beautyleg]2010.06.18 No.414 Avy[73P]\\60.jpg",550,250);
                builder.InsertImage(dt.Rows[1][2].ToString(), 450, 200);
               // doc.Range.Bookmarks["Z_IMG_41"].Text = "";

            }
            #endregion
        }
Example #34
0
        public void GetHashCodeEx()
        {
            //ExStart
            //ExFor:GetHashCode
            //ExId:GetHashCodeEx
            //ExSummary:Shows how to use GetHashCode.
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Document.doc");
            Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
            Aspose.Words.Border border = builder.Font.Border;

            int hash = border.GetHashCode();
            //ExEnd
        }
Example #35
0
        /// <summary>
        /// 设计参数
        /// </summary>
        public void ExpWD3(System.Data.DataTable dt3)
        {
            #region //添加表格4.3
            try{
            builder = new Aspose.Words.DocumentBuilder(doc);
            builder.MoveToBookmark("Z_A43_B_1");
             for (var i = 0; i < dt3.Rows.Count; i++)
                {
                    for (var j = 0; j < dt3.Columns.Count-1; j++)
                    {
                        builder.InsertCell();// 添加一个单元格
                        //builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                        //builder.CellFormat.Borders.LineWidth = 2;
                        if(i==0)
                        {
                            builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;
                            builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Top.LineWidth = 2;

                        }else if (i == dt3.Rows.Count-1)
                        {
                            builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;
                            builder.CellFormat.Borders.Right.LineStyle = LineStyle.None;
                            builder.CellFormat.Borders.Bottom.LineWidth = 2;
                        }else{
                            builder.CellFormat.Borders.LineWidth = 1;
                            builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Left.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;

                        }
                        if (j == 0)
                        {
                            builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;

                        }
                        else if (j == dt3.Columns.Count - 2)
                        {
                            builder.CellFormat.Borders.Right.LineStyle = LineStyle.None;
                        }
                        else
                        {
                            builder.CellFormat.Borders.Left.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;
                        }

                        builder.CellFormat.Borders.Color = System.Drawing.Color.Black;
                        builder.CellFormat.Width = 100;
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;//垂直居中对齐
                        builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;//水平居中对齐
                        if (j == 0) { builder.CellFormat.Width = 60; }
                        else if (j == 1) { builder.CellFormat.Width = 120; }
                        else if (j == 2) { builder.CellFormat.Width = 120; }
                        else if (j == 3) { builder.CellFormat.Width = 80; }
                        else if (j == 4) { builder.CellFormat.Width = 80; }
                        else if (j == 5) { builder.CellFormat.Width = 100; }
                        builder.Write(dt3.Rows[i][j].ToString());

                    }

                    builder.EndRow();
                }
            //    doc.Range.Bookmarks["cs"].Text = "";    // 清掉标示
            }
            catch (Exception e)
            {
                MessageUtil.ShowWarning(e.Message.ToString());
            }
            #endregion
        }
Example #36
0
        /// <summary>
        /// 负荷参数
        /// </summary>
        public void ExpWD4(System.Data.DataTable dt)
        {
            #region //表格4.2
            try
            {
                builder = new Aspose.Words.DocumentBuilder(doc);
                builder.MoveToBookmark("Z_A42_B_1");        //开始添加值
                for (var i = 0; i < dt.Rows.Count; i++)
                {
                    for (var j = 0; j < dt.Columns.Count - 1; j++)
                    {
                        builder.InsertCell();// 添加一个单元格
                        //builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                        //builder.CellFormat.Borders.LineWidth = 2;

                        if (i == 0)
                        {
                            builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;
                            builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Top.LineWidth = 2;
                         //   builder.Font.Subscript = true;

                        }
                        else if (i == dt.Rows.Count - 1)
                        {
                            builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;
                            builder.CellFormat.Borders.Right.LineStyle = LineStyle.None;
                            builder.CellFormat.Borders.Bottom.LineWidth = 2;
                        }
                        else
                        {
                            builder.CellFormat.Borders.LineWidth = 1;
                            builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Left.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;

                        }
                        if (j == 0)
                        {
                            builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;

                        }
                        else if (j == dt.Columns.Count - 2)
                        {
                            builder.CellFormat.Borders.Right.LineStyle = LineStyle.None;
                        }
                        else
                        {
                            builder.CellFormat.Borders.Left.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;
                        }

                        builder.CellFormat.Borders.Color = System.Drawing.Color.Black;
                        builder.CellFormat.Width = 100;
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;//垂直居中对齐
                        builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;//水平居中对齐
                        if (j == 0) { builder.CellFormat.Width = 60; }
                        else if (j == 1) { builder.CellFormat.Width = 120; }
                        else if (j == 2) { builder.CellFormat.Width = 120; }
                        else if (j == 3) { builder.CellFormat.Width = 80; }
                        else if (j == 4) { builder.CellFormat.Width = 80; }
                        else if (j == 5) { builder.CellFormat.Width = 100; }
                        builder.Write(dt.Rows[i][j].ToString().Replace("(B1)", "").Replace("(B2)", "").Replace("(B3)", "").Replace("(B4)", "").Replace("(L1)", "").Replace("(L2)", "").Replace("(L3)", "").Replace("(L4)", ""));

                    }
                    builder.EndRow();
                }
                if( Convert.ToDouble(dt.Rows[2][2].ToString()).ToString("0.00") == "0.00")
                {
                 builder.MoveToBookmark("BZ1");
                 Row row = (Row)builder.CurrentNode.GetAncestor(NodeType.Row);
                 if (row != null) row.Remove();
                }
            }
            catch (Exception e)
            {
                MessageUtil.ShowWarning(e.Message.ToString());
            }
            #endregion
        }
Example #37
0
        public void ExpWD6(System.Data.DataTable dt6)
        {
            builder = new Aspose.Words.DocumentBuilder(doc);

            bookmark = doc.Range.Bookmarks["Z_A50_1"];
            if (bookmark != null)
            {
                bookmark.Text = dt6.Rows[20][6].ToString();
            }

            builder.MoveToBookmark("Z_A51_B_1");
            for (var i = 0; i < dt6.Rows.Count; i++)
            {
                for (var j = 0; j < dt6.Columns.Count - 1; j++)
                {
                    builder.InsertCell();
                    if (i == 0)
                    {
                        builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Top.LineWidth = 2;

                    }
                    else if (i == dt6.Rows.Count - 1)
                    {
                        builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.None;
                        builder.CellFormat.Borders.Bottom.LineWidth = 2;
                    }
                    else
                    {
                        builder.CellFormat.Borders.LineWidth = 1;
                        builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;

                    }
                    if (j == 0)
                    {
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;

                    }
                    else if (j == dt6.Columns.Count - 2)
                    {
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.None;
                    }
                    else
                    {
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;
                    }

                    //单元格合并
                    /*
                    if ((i >= 3 &&i <= 4) && j == 0)
                    {
                        if (i == 3) { builder.CellFormat.VerticalMerge = CellMerge.First; } else { builder.CellFormat.VerticalMerge = CellMerge.Previous; }
                    }
                    else if ((i >= 5 && i <=8) && j == 0)
                    {
                        if (i == 5) { builder.CellFormat.VerticalMerge = CellMerge.First; } else { builder.CellFormat.VerticalMerge = CellMerge.Previous; }
                    }
                    else if ((i >= 9 && i <= 11) && j == 0)
                    {
                        if (i == 9) { builder.CellFormat.VerticalMerge = CellMerge.First; } else { builder.CellFormat.VerticalMerge = CellMerge.Previous; }
                    }
                    else if ((i >= 12 && i <= 13) && j == 0)
                    {
                        if (i == 12) { builder.CellFormat.VerticalMerge = CellMerge.First; } else { builder.CellFormat.VerticalMerge = CellMerge.Previous; }
                    }
                    else if ((i >= 18 && i <= 19) && j == 0)
                    {
                        if (i == 18) { builder.CellFormat.VerticalMerge = CellMerge.First; } else { builder.CellFormat.VerticalMerge = CellMerge.Previous; }
                    }
                    else
                    {
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                    }
                    */

                    builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                    builder.CellFormat.Borders.Color = System.Drawing.Color.Black;
                    builder.CellFormat.Width = 100;
                    builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;//垂直居中对齐
                    builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;//水平居中对齐

                    if (j == 0) { builder.CellFormat.Width = 60; }
                    else if (j == 1) { builder.CellFormat.Width = 120; }
                    else if (j == 2) { builder.CellFormat.Width = 120; }
                    else if (j == 3) { builder.CellFormat.Width = 80; }
                    else if (j == 4) { builder.CellFormat.Width = 80; }
                    else if (j == 5) { builder.CellFormat.Width = 100; }
                    else if (j == 5) { builder.CellFormat.Width = 100; }
                    else if (j == 5) { builder.CellFormat.Width = 80; }
                    builder.Write(dt6.Rows[i][j].ToString());
                }

                builder.EndRow();
            }

            /*
            builder.MoveToBookmark("Z_A51_B_1");
            Aspose.Words.Tables.Table table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);
            int i = 0;
            if (dt6.Rows.Count > 0)
            {
                builder.InsertCell();
                builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                builder.CellFormat.Borders.Color = System.Drawing.Color.Black;
                builder.CellFormat.VerticalMerge = CellMerge.None;
                builder.Write("Text in one cell");
                builder.EndRow();

                //设置单元格属性,合并单元格
                table.Rows[4].Cells[0].CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.First;
                for (int j = 0; j < dt6.Rows.Count - 1; j++)
                {
                    Aspose.Words.Tables.Row beforeRow = table.Rows[i++];
                    Aspose.Words.Tables.Row clonedRow = (Aspose.Words.Tables.Row)beforeRow.Clone(true);
                    table.InsertAfter(clonedRow, beforeRow);//插入到指定位置下面
                    DataRow dr = dt6.Rows[j];
                    //修改上行内容
                    builder.MoveToCell(0, i - 1, 1, 0);
                    builder.Write(dr[1].ToString());
                    //设置合并内容
               //     builder.MoveToCell(0, i, 0, 0);
                    builder.CellFormat.WrapText = true;
                    //合并单元格
                    clonedRow.Cells[0].CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
                }

                builder.MoveToCell(0, i, 1, 0);
                builder.Write(dt6.Rows[dt6.Rows.Count - 1][1].ToString());
            }
             * */
        }
Example #38
0
        public void ExpWD8(System.Data.DataTable dt8)
        {
            builder = new Aspose.Words.DocumentBuilder(doc);

            builder.MoveToBookmark("Z_A62_B_1");
            for (var i = 0; i < dt8.Rows.Count; i++)
            {
                for (var j = 0; j < dt8.Columns.Count - 1; j++)
                {
                    builder.InsertCell();
                    if (i == 0)
                    {
                        builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Top.LineWidth = 2;

                    }
                    else if (i == dt8.Rows.Count - 1)
                    {
                        builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.None;
                        builder.CellFormat.Borders.Bottom.LineWidth = 2;
                    }
                    else
                    {
                        builder.CellFormat.Borders.LineWidth = 1;
                        builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;

                    }
                    if (j == 0)
                    {
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;

                    }
                    else if (j == dt8.Columns.Count - 2)
                    {
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.None;
                    }
                    else
                    {
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;
                    }

                    //单元格合并

                    if ((i >= 4 &&i <= 5) && (j == 0||j==1))
                    {
                        if (i == 4) { builder.CellFormat.VerticalMerge = CellMerge.First; } else { builder.CellFormat.VerticalMerge = CellMerge.Previous; }
                    }
                    else if ((i >= 6 && i <= 7) && (j == 0 || j == 1))
                    {
                        if (i == 6) { builder.CellFormat.VerticalMerge = CellMerge.First; } else { builder.CellFormat.VerticalMerge = CellMerge.Previous; }
                    }
                    else if ((i >= 8 && i <= 13) && (j == 0 || j == 1))
                    {
                        if (i == 8) { builder.CellFormat.VerticalMerge = CellMerge.First; } else { builder.CellFormat.VerticalMerge = CellMerge.Previous; }
                    }
                    else
                    {
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                    }

             //           builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                    builder.CellFormat.Borders.Color = System.Drawing.Color.Black;
                    builder.CellFormat.Width = 100;
                    builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;//垂直居中对齐
                    builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;//水平居中对齐

                    if (j == 0) { builder.CellFormat.Width = 60; }
                    else if (j == 1) { builder.CellFormat.Width = 120; }
                    else if (j == 2) { builder.CellFormat.Width = 120; }
                    else if (j == 3) { builder.CellFormat.Width = 80; }
                    else if (j == 4) { builder.CellFormat.Width = 80; }
                    else if (j == 5) { builder.CellFormat.Width = 100; }
                    else if (j == 6) { builder.CellFormat.Width = 100; }
                    else if (j == 7) { builder.CellFormat.Width = 80; }
                    else if (j == 8) { builder.CellFormat.Width = 80; }
                    builder.Write(dt8.Rows[i][j].ToString());

                }

                builder.EndRow();

            }
            bookmark = doc.Range.Bookmarks["Z_A62_4"];
            bookmark.Text = dt8.Rows[6][3].ToString();
        }