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 }
private AsposeDocAdapter(string fileName) { DocumentFile = fileName; Aspose.Words.Document doc = new Aspose.Words.Document(fileName); Aspose.Words.NodeCollection tables = doc.GetChildNodes(Aspose.Words.NodeType.Table, true); int count = tables.Count; if (count == 0) { throw new SystemException("No table found in document " + fileName); } table = (Aspose.Words.Tables.Table)tables[0]; Aspose.Words.Node node = table; while (node.PreviousSibling != null) { node = node.PreviousSibling; } string text = ""; while (node.NextSibling != table) { text += node.ToString(); node = node.NextSibling; } title = text; }
public void ClearAllAttrsEx() { //ExStart //ExFor:TabStopCollection.Clear //ExSummary:Shows how to clear a document of all tab stops. Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Document.TableOfContents.doc"); foreach (Aspose.Words.Paragraph para in doc.GetChildNodes(Aspose.Words.NodeType.Paragraph, true)) { para.ParagraphFormat.TabStops.Clear(); } doc.Save(ExDir + "Document.AllTabStopsRemoved Out.doc"); //ExEnd }
/// <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()); } }