public void AddEx() { //ExStart //ExFor:TabStopCollection.Add(TabStop) //ExFor:TabStopCollection.Add(Double, TabAlignment, TabLeader) //ExSummary:Shows how to create tab stops and add them to a document. Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Document.doc"); Aspose.Words.Paragraph paragraph = (Aspose.Words.Paragraph)doc.GetChild(Aspose.Words.NodeType.Paragraph, 0, true); // Create a TabStop object and add it to the document. Aspose.Words.TabStop tabStop = new Aspose.Words.TabStop(Aspose.Words.ConvertUtil.InchToPoint(3), Aspose.Words.TabAlignment.Left, Aspose.Words.TabLeader.Dashes); paragraph.ParagraphFormat.TabStops.Add(tabStop); // Add a tab stop without explicitly creating new TabStop objects. paragraph.ParagraphFormat.TabStops.Add(Aspose.Words.ConvertUtil.MillimeterToPoint(100), Aspose.Words.TabAlignment.Left, Aspose.Words.TabLeader.Dashes); // Add tab stops at 5 cm to all paragraphs. foreach (Aspose.Words.Paragraph para in doc.GetChildNodes(Aspose.Words.NodeType.Paragraph, true)) { para.ParagraphFormat.TabStops.Add(Aspose.Words.ConvertUtil.MillimeterToPoint(50), Aspose.Words.TabAlignment.Left, Aspose.Words.TabLeader.Dashes); } doc.Save(ExDir + "Document.AddedTabStops Out.doc"); //ExEnd }
public void GetPositionByIndexEx() { //ExStart //ExFor:TabStopCollection.GetPositionByIndex //ExSummary:Shows how to find a tab by it's index and get its position. Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Document.doc"); Aspose.Words.Paragraph paragraph = (Aspose.Words.Paragraph)doc.GetChild(Aspose.Words.NodeType.Paragraph, 0, true); paragraph.ParagraphFormat.TabStops.Add(85, Aspose.Words.TabAlignment.Left, Aspose.Words.TabLeader.Dashes); paragraph.ParagraphFormat.TabStops.Add(170, Aspose.Words.TabAlignment.Left, Aspose.Words.TabLeader.Dashes); Console.WriteLine(paragraph.ParagraphFormat.TabStops.GetPositionByIndex(1)); // 170 //ExEnd }
public void GetIndexByPositionEx() { //ExStart //ExFor:TabStopCollection.GetIndexByPosition //ExSummary:Shows how to look up a position to see if a tab stop exists there, and if so, obtain its index. Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Document.doc"); Aspose.Words.Paragraph paragraph = (Aspose.Words.Paragraph)doc.GetChild(Aspose.Words.NodeType.Paragraph, 0, true); paragraph.ParagraphFormat.TabStops.Add(Aspose.Words.ConvertUtil.MillimeterToPoint(30), Aspose.Words.TabAlignment.Left, Aspose.Words.TabLeader.Dashes); // An output of -1 signifies that there is no tab stop at that position. Console.WriteLine(paragraph.ParagraphFormat.TabStops.GetIndexByPosition(Aspose.Words.ConvertUtil.MillimeterToPoint(30))); // 0 Console.WriteLine(paragraph.ParagraphFormat.TabStops.GetIndexByPosition(Aspose.Words.ConvertUtil.MillimeterToPoint(60))); // -1 //ExEnd }
public void AddEx() { //ExStart //ExFor:TabStopCollection.Add(TabStop) //ExFor:TabStopCollection.Add(Double, TabAlignment, TabLeader) //ExSummary:Shows how to create and add tabStop objects to a document. Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Document.doc"); Aspose.Words.Paragraph paragraph = (Aspose.Words.Paragraph)doc.GetChild(Aspose.Words.NodeType.Paragraph, 0, true); // Create a TabStop object and add it into the document Aspose.Words.TabStop tabStop = new Aspose.Words.TabStop(84.99, Aspose.Words.TabAlignment.Left, Aspose.Words.TabLeader.Dashes); paragraph.ParagraphFormat.TabStops.Add(tabStop); // Add a TabStop without explicitly initializing paragraph.ParagraphFormat.TabStops.Add(169.98, Aspose.Words.TabAlignment.Left, Aspose.Words.TabLeader.Dashes); doc.Save(ExDir + "Document.AddedTabStops Out.doc"); //ExEnd }
public void GetPositionByIndexEx() { //ExStart //ExFor:TabStopCollection.GetPositionByIndex //ExSummary:Shows how to find a tab stop by it's index and get its position. Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Document.doc"); Aspose.Words.Paragraph paragraph = (Aspose.Words.Paragraph)doc.GetChild(Aspose.Words.NodeType.Paragraph, 0, true); paragraph.ParagraphFormat.TabStops.Add(Aspose.Words.ConvertUtil.MillimeterToPoint(30), Aspose.Words.TabAlignment.Left, Aspose.Words.TabLeader.Dashes); paragraph.ParagraphFormat.TabStops.Add(Aspose.Words.ConvertUtil.MillimeterToPoint(60), Aspose.Words.TabAlignment.Left, Aspose.Words.TabLeader.Dashes); Console.WriteLine("Tab stop at index {0} of the first paragraph is at {1} points.", 1, paragraph.ParagraphFormat.TabStops.GetPositionByIndex(1)); //ExEnd }
public void RemoveByIndexEx() { //ExStart //ExFor:TabStopCollection.RemoveByIndex //ExSummary:Shows how to select a tab stop in a document by it's index and remove it. Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Document.doc"); Aspose.Words.Paragraph paragraph = (Aspose.Words.Paragraph)doc.GetChild(Aspose.Words.NodeType.Paragraph, 0, true); paragraph.ParagraphFormat.TabStops.Add(Aspose.Words.ConvertUtil.MillimeterToPoint(30), Aspose.Words.TabAlignment.Left, Aspose.Words.TabLeader.Dashes); paragraph.ParagraphFormat.TabStops.Add(Aspose.Words.ConvertUtil.MillimeterToPoint(60), Aspose.Words.TabAlignment.Left, Aspose.Words.TabLeader.Dashes); // Tab stop placed at 30 mm is removed paragraph.ParagraphFormat.TabStops.RemoveByIndex(0); Console.WriteLine(paragraph.ParagraphFormat.TabStops.Count); doc.Save(ExDir + "Document.RemovedTabStopsByIndex Out.doc"); //ExEnd }
public static string Process(DocOptions options) { string result = ""; try { var config = ConfigHelpers.GetDefaultConfig(options.Config); IDatabase database = new Database(config, LogHelpers.LogStatic, option => { //option.CodeGenProjectName = projectName; //option.CodeGenNameSpace = nameSpace; //option.CodeGenTableFilter = tablePrefixFilter; //option.AutoMigrateOnContainTable = onlyTable; }); string type = options.Type; var projectConfig = DbLoader.ConvertDatabaseConfigToProjectConfig(database); LogHelpers.LogStatic(projectConfig.ToString()); string msg = ""; var tables = DbLoader.GetTableInfos(database, projectConfig, null, null, out msg); LogHelpers.LogStatic(msg); string docName = projectConfig.DatabaseName; OutputContext _OutputContext = new OutputContext(); _OutputContext.Tables = tables; // context.Mappers = mapperDict; _OutputContext.ProjectConfig = projectConfig; //context.ParserConfig = _parseConfig; string FileName = docName + "数据库设计文档." + type; string RealOutputFileName = System.IO.Path.Combine(DbLoader.GetProjectDirectory(projectConfig), FileName); if (type == "html") { string templatePath = DbLoader.MapPath("~/DocGen/dicthtml.cshtml"); if (System.IO.File.Exists(templatePath)) { string tempalteContent = FileHelper.ReadFile(templatePath); string key = "exportdicthtml"; var templateEngine = DbLoader.CreateTemplateEngine(); var generateResult = templateEngine.Parse <OutputContext>(tempalteContent, key, _OutputContext); string content = generateResult; templateEngine.OutputResult(RealOutputFileName, content); //return File(RealOutputFileName, "application/zip-x-compressed", FileName); } } else { //Other types string tmppath = DbLoader.MapPath("~/DocGen/dict.dot"); // System.IO.Path.Combine(path, "Template", "template.dot"); Aspose.Words.Document doc = new Aspose.Words.Document(tmppath); //载入模板 Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc); string dbName = docName; if (string.IsNullOrEmpty(dbName)) { dbName = _OutputContext.ProjectConfig.Name; } doc.Range.Replace("{$.DBName}", dbName, false, false); Aspose.Words.Tables.Table tabletemp = (Aspose.Words.Tables.Table)doc.GetChild(Aspose.Words.NodeType.Table, 0, true); Aspose.Words.Tables.Table tableClone = (Aspose.Words.Tables.Table)tabletemp.Clone(true); for (int k = 0; k < _OutputContext.Tables.Count; k++) { Aspose.Words.Tables.Table table = (Aspose.Words.Tables.Table)doc.GetChild(Aspose.Words.NodeType.Table, k, true); var tb = _OutputContext.Tables[k]; //添加表头标题 var par = table.ParentNode.InsertBefore(new Aspose.Words.Paragraph(doc), table); builder.MoveTo(par); builder.ParagraphFormat.StyleIdentifier = Aspose.Words.StyleIdentifier.Heading1; builder.Font.Size = 11; builder.Write(tb.Comment + "(" + tb.Name + ")"); Aspose.Words.Tables.Cell cellh = table.FirstRow.Cells[1]; cellh.RemoveAllChildren(); builder.MoveToCell(k, 0, 1, 0); builder.Write(tb.Name); Aspose.Words.Tables.Cell cellh3 = table.FirstRow.Cells[3]; cellh3.RemoveAllChildren(); builder.MoveToCell(k, 0, 3, 0); builder.Write(tb.Comment != null ? tb.Comment : ""); for (int i = 0; i < tb.Columns.Count; i++) { for (int j = 0; j < table.LastRow.Cells.Count; j++) { Aspose.Words.Tables.Cell cell = table.LastRow.Cells[j]; cell.RemoveAllChildren(); builder.MoveToCell(k, table.Rows.Count - 1, j, 0); switch (j) { case 0: builder.Write(tb.Columns[i].Comment != null ? tb.Columns[i].Comment : ""); break; case 1: builder.Write(tb.Columns[i].Name); break; case 2: builder.Write(tb.Columns[i].RawType); break; case 3: builder.Write(tb.Columns[i].Length.ToString()); break; case 4: builder.Write(tb.Columns[i].Scale.ToString()); break; case 5: builder.Write(tb.Columns[i].IsPK ? "Y" : ""); break; case 6: builder.Write(tb.Columns[i].IsNullable ? "Y" : ""); break; case 7: builder.Write(tb.Columns[i].IsAutoIncrement ? "Y" : ""); break; case 8: builder.Write(tb.Columns[i].DefaultValue == null ? "" : tb.Columns[i].DefaultValue.ToString()); break; default: break; } } if (i < tb.Columns.Count - 1) { Aspose.Words.Tables.Row clonedRow = (Aspose.Words.Tables.Row)table.LastRow.Clone(true); table.AppendChild(clonedRow); } } if (k < _OutputContext.Tables.Count - 1) { Aspose.Words.Tables.Table tbClone = (Aspose.Words.Tables.Table)tableClone.Clone(true); table.ParentNode.InsertAfter(tbClone, table); } } doc.UpdateFields(); doc.Range.Replace("{$.NowDateTime}", DateTime.Now.ToString(), false, false); Aspose.Words.SaveFormat sformat = Aspose.Words.SaveFormat.Doc; switch (type) { case "doc": sformat = Aspose.Words.SaveFormat.Doc; break; case "docx": sformat = Aspose.Words.SaveFormat.Docx; break; //case "html": // sformat = Aspose.Words.SaveFormat.Html; // break; case "odt": sformat = Aspose.Words.SaveFormat.Odt; break; case "pdf": sformat = Aspose.Words.SaveFormat.Pdf; break; case "png": sformat = Aspose.Words.SaveFormat.Png; break; case "tiff": sformat = Aspose.Words.SaveFormat.Tiff; break; case "text": sformat = Aspose.Words.SaveFormat.Text; break; case "epub": sformat = Aspose.Words.SaveFormat.Epub; break; default: break; } doc.Save(RealOutputFileName, sformat); //return File(RealOutputFileName, "application/zip-x-compressed", FileName); } if (options.Zip) { var zipDir = RealOutputFileName; string zipedName = docName + "-" + System.DateTime.Now.ToString("yyyyMMddHHmmss") + ".zip"; string zipOutFileName = System.IO.Path.Combine(DbLoader.GetDataDirectory(), zipedName); //ZipHelper.ZipDir(zipDir, zipOutFileName, 9); //ZipHelper.ZipManyFilesOrDictorys(zipDir, zipOutFileName, ""); ZipHelper.ZipFile(zipDir, zipOutFileName); RealOutputFileName = zipOutFileName; } LogHelpers.LogStatic("生成数据库字典成功:" + RealOutputFileName); ConfigHelpers.OpenDir(RealOutputFileName); } catch (Exception ex) { LogHelpers.LogStatic("DocGenerator 生成数据库字典出错!", ex, Pure.Data.MessageType.Error); } return(result); }
/// <summary> /// 转换到PDF文件 /// </summary> /// <param name="destDocFile"></param> private void convertToPDF(string projectNumber, string destDocFile) { try { //Document文档对象 Aspose.Words.Document xDoc = new Aspose.Words.Document(destDocFile); //获得附件表格 Aspose.Words.Tables.Table tablee = (Aspose.Words.Tables.Table)xDoc.GetChild(Aspose.Words.NodeType.Table, xDoc.GetChildNodes(Aspose.Words.NodeType.Table, true).Count - 1, true); //行与 int rowIndex = 0; //查找需要替换位置 if (tablee != null && tablee.Rows != null) { //表格有效 foreach (Aspose.Words.Tables.Row row in tablee.Rows) { if (row.Cells[0].GetText().Contains("序号")) { continue; } else { //行号+1 rowIndex++; //清理单位格内容 row.Cells[0].Paragraphs.Clear(); //写行号 Aspose.Words.Paragraph p = new Aspose.Words.Paragraph(xDoc); p.AppendChild(new Aspose.Words.Run(xDoc, rowIndex.ToString())); row.Cells[0].AppendChild(p); } } } else { //表格无效 MainForm.writeLog("没有找到附件清单,当前文件" + destDocFile + ",表格数量:" + xDoc.GetChildNodes(Aspose.Words.NodeType.Table, true).Count); } //保存为PDF xDoc.Save(Path.Combine(new FileInfo(destDocFile).DirectoryName, "项目申报书.pdf"), Aspose.Words.SaveFormat.Pdf); } catch (Exception ex) { MainForm.writeLog(ex.ToString()); //尝试取文件名称 string fileName = destDocFile; try { fileName = new FileInfo(destDocFile).Name; } catch (Exception exxx) { } //检查是不是出现了保存成PDF时内存溢出 addErrorFile(projectNumber, fileName, "PDF转换失败"); } //删除Doc文档 try { File.Delete(destDocFile); } catch (Exception ex) { MainForm.writeLog(ex.ToString()); } }
public void RemoveByIndexEx() { //ExStart //ExFor:TabStopCollection.RemoveByIndex //ExSummary:Shows how to select a TabStop in a document by it's index and remove it. Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Document.doc"); Aspose.Words.Paragraph paragraph = (Aspose.Words.Paragraph)doc.GetChild(Aspose.Words.NodeType.Paragraph, 0, true); paragraph.ParagraphFormat.TabStops.Add(84.99, Aspose.Words.TabAlignment.Left, Aspose.Words.TabLeader.Dashes); paragraph.ParagraphFormat.TabStops.Add(169.98, Aspose.Words.TabAlignment.Left, Aspose.Words.TabLeader.Dashes); // TabStop at 84.99 points is removed paragraph.ParagraphFormat.TabStops.RemoveByIndex(0); doc.Save(ExDir + "Document.RemovedTabStopsByIndex Out.doc"); //ExEnd }