public void UpdateTableLayout() { //ExStart //ExFor:Document.UpdateTableLayout //ExSummary:Shows how to preserve a table's layout when saving to .txt. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Table table = builder.StartTable(); builder.InsertCell(); builder.Write("Cell 1"); builder.InsertCell(); builder.Write("Cell 2"); builder.InsertCell(); builder.Write("Cell 3"); builder.EndTable(); // Create a SaveOptions object to prepare this document to be saved to .txt. TxtSaveOptions options = new TxtSaveOptions(); options.PreserveTableLayout = true; // Previewing the appearance of the document in .txt form shows that the table will not be represented accurately. Assert.AreEqual(0.0d, table.FirstRow.Cells[0].CellFormat.Width); Assert.AreEqual("CCC\r\neee\r\nlll\r\nlll\r\n \r\n123\r\n\r\n", doc.ToString(options)); // We can call UpdateTableLayout() to fix some of these issues. doc.UpdateTableLayout(); Assert.AreEqual("Cell 1 Cell 2 Cell 3\r\n\r\n", doc.ToString(options)); Assert.AreEqual(155.0d, table.FirstRow.Cells[0].CellFormat.Width, 2f); //ExEnd }
public void Encoding() { //ExStart //ExFor:TxtSaveOptionsBase.Encoding //ExSummary:Shows how to set encoding for a .txt output document. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Add some text with characters from outside the ASCII character set. builder.Write("À È Ì Ò Ù."); // Create a "TxtSaveOptions" object, which we can pass to the document's "Save" method // to modify how we save the document to plaintext. TxtSaveOptions txtSaveOptions = new TxtSaveOptions(); // Verify that the "Encoding" property contains the appropriate encoding for our document's contents. Assert.AreEqual(System.Text.Encoding.UTF8, txtSaveOptions.Encoding); doc.Save(ArtifactsDir + "TxtSaveOptions.Encoding.UTF8.txt", txtSaveOptions); string docText = System.Text.Encoding.UTF8.GetString(File.ReadAllBytes(ArtifactsDir + "TxtSaveOptions.Encoding.UTF8.txt")); Assert.AreEqual("\uFEFFÀ È Ì Ò Ù.\r\n", docText); // Using an unsuitable encoding may result in a loss of document contents. txtSaveOptions.Encoding = System.Text.Encoding.ASCII; doc.Save(ArtifactsDir + "TxtSaveOptions.Encoding.ASCII.txt", txtSaveOptions); docText = System.Text.Encoding.ASCII.GetString(File.ReadAllBytes(ArtifactsDir + "TxtSaveOptions.Encoding.ASCII.txt")); Assert.AreEqual("? ? ? ? ?.\r\n", docText); //ExEnd }
public void AddBidiMarks(bool addBidiMarks) { //ExStart //ExFor:TxtSaveOptions.AddBidiMarks //ExSummary:Shows how to insert Unicode Character 'RIGHT-TO-LEFT MARK' (U+200F) before each bi-directional Run in text. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("Hello world!"); builder.ParagraphFormat.Bidi = true; builder.Writeln("שלום עולם!"); builder.Writeln("مرحبا بالعالم!"); TxtSaveOptions saveOptions = new TxtSaveOptions { AddBidiMarks = addBidiMarks, Encoding = System.Text.Encoding.Unicode }; doc.Save(ArtifactsDir + "TxtSaveOptions.AddBidiMarks.txt", saveOptions); string docText = System.Text.Encoding.Unicode.GetString(File.ReadAllBytes(ArtifactsDir + "TxtSaveOptions.AddBidiMarks.txt")); if (addBidiMarks) { Assert.AreEqual("\uFEFFHello world!\r\nשלום עולם!\r\nمرحبا بالعالم!\r\n\r\n", docText); Assert.True(docText.Contains("\u200f")); } else { Assert.AreEqual("\uFEFFHello world!\r\nשלום עולם!\r\nمرحبا بالعالم!\r\n\r\n", docText); Assert.False(docText.Contains("\u200f")); } //ExEnd }
public void PageBreaks(bool forcePageBreaks) { //ExStart //ExFor:TxtSaveOptionsBase.ForcePageBreaks //ExSummary:Shows how to specify whether the page breaks should be preserved during export. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("Page 1"); builder.InsertBreak(BreakType.PageBreak); builder.Writeln("Page 2"); builder.InsertBreak(BreakType.PageBreak); builder.Writeln("Page 3"); // If ForcePageBreaks is set to true then the output document will have form feed characters in place of page breaks // Otherwise, they will be line breaks TxtSaveOptions saveOptions = new TxtSaveOptions { ForcePageBreaks = forcePageBreaks }; doc.Save(ArtifactsDir + "TxtSaveOptions.PageBreaks.txt", saveOptions); // If we load the document using Aspose.Words again, the page breaks will be preserved/lost depending on ForcePageBreaks doc = new Document(ArtifactsDir + "TxtSaveOptions.PageBreaks.txt"); Assert.AreEqual(forcePageBreaks ? 3 : 1, doc.PageCount); //ExEnd TestUtil.FileContainsString( forcePageBreaks ? "Page 1\r\n\fPage 2\r\n\fPage 3\r\n\r\n" : "Page 1\r\nPage 2\r\nPage 3\r\n\r\n", ArtifactsDir + "TxtSaveOptions.PageBreaks.txt"); }
public void ParagraphBreak() { //ExStart //ExFor:TxtSaveOptions //ExFor:TxtSaveOptions.SaveFormat //ExFor:TxtSaveOptionsBase //ExFor:TxtSaveOptionsBase.ParagraphBreak //ExSummary:Shows how to save a .txt document with a custom paragraph break. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("Paragraph 1."); builder.Writeln("Paragraph 2."); builder.Write("Paragraph 3."); // Create a "TxtSaveOptions" object, which we can pass to the document's "Save" method // to modify how we save the document to plaintext. TxtSaveOptions txtSaveOptions = new TxtSaveOptions(); Assert.AreEqual(SaveFormat.Text, txtSaveOptions.SaveFormat); // Set the "ParagraphBreak" to a custom value that we wish to put at the end of every paragraph. txtSaveOptions.ParagraphBreak = " End of paragraph.\n\n\t"; doc.Save(ArtifactsDir + "TxtSaveOptions.ParagraphBreak.txt", txtSaveOptions); string docText = File.ReadAllText(ArtifactsDir + "TxtSaveOptions.ParagraphBreak.txt"); Assert.AreEqual("Paragraph 1. End of paragraph.\n\n\t" + "Paragraph 2. End of paragraph.\n\n\t" + "Paragraph 3. End of paragraph.\n\n\t", docText); //ExEnd }
public void ParagraphBreak() { //ExStart //ExFor:TxtSaveOptions //ExFor:TxtSaveOptions.SaveFormat //ExFor:TxtSaveOptionsBase //ExFor:TxtSaveOptionsBase.ParagraphBreak //ExSummary:Shows how to save a .txt document with a custom paragraph break. // Create a new document and add some paragraphs Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("Paragraph 1."); builder.Writeln("Paragraph 2."); builder.Write("Paragraph 3."); // When saved to plain text, the paragraphs we created can be separated by a custom string TxtSaveOptions txtSaveOptions = new TxtSaveOptions { SaveFormat = SaveFormat.Text, ParagraphBreak = " End of paragraph.\n\n\t" }; doc.Save(ArtifactsDir + "TxtSaveOptions.ParagraphBreak.txt", txtSaveOptions); string docText = File.ReadAllText(ArtifactsDir + "TxtSaveOptions.ParagraphBreak.txt"); Assert.AreEqual("Paragraph 1. End of paragraph.\n\n\t" + "Paragraph 2. End of paragraph.\n\n\t" + "Paragraph 3. End of paragraph.\n\n\t", docText); //ExEnd }
public static void ExportHeadersFootersMode(string dataDir) { //ExStart:ExportHeadersFootersMode Document doc = new Document(dataDir + "TxtExportHeadersFootersMode.docx"); TxtSaveOptions options = new TxtSaveOptions(); options.SaveFormat = SaveFormat.Text; // All headers and footers are placed at the very end of the output document. options.ExportHeadersFootersMode = TxtExportHeadersFootersMode.AllAtEnd; doc.Save(dataDir + "outputFileNameA.txt", options); // Only primary headers and footers are exported at the beginning and end of each section. options.ExportHeadersFootersMode = TxtExportHeadersFootersMode.PrimaryOnly; doc.Save(dataDir + "outputFileNameB.txt", options); // No headers and footers are exported. options.ExportHeadersFootersMode = TxtExportHeadersFootersMode.None; doc.Save(dataDir + "outputFileNameC.txt", options); //ExEnd:ExportHeadersFootersMode Console.WriteLine("\nExport text files with TxtExportHeadersFootersMode.\nFiles saved at " + dataDir); }
public void AddBidiMarks() { //ExStart //ExFor:TxtSaveOptions.AddBidiMarks //ExSummary:Shows how to insert Unicode Character 'RIGHT-TO-LEFT MARK' (U+200F) before each bi-directional Run in text. Document doc = new Document(MyDir + "Document.docx"); // In Aspose.Words by default this option is set to true unlike Word TxtSaveOptions saveOptions = new TxtSaveOptions { AddBidiMarks = false }; doc.Save(MyDir + @"\Artifacts\AddBidiMarks.txt", saveOptions); //ExEnd }
public void PageBreaks() { //ExStart //ExFor:TxtSaveOptions.ForcePageBreaks //ExSummary:Shows how to specify whether the page breaks should be preserved during export. Document doc = new Document(MyDir + "SaveOptions.PageBreaks.docx"); TxtSaveOptions saveOptions = new TxtSaveOptions { ForcePageBreaks = false }; doc.Save(MyDir + @"\Artifacts\SaveOptions.PageBreaks.txt", saveOptions); //ExEnd }
public static void AddBidiMarks(string dataDir) { //ExStart:AddBidiMarks Document doc = new Document(dataDir + "Input.docx"); TxtSaveOptions saveOptions = new TxtSaveOptions(); saveOptions.AddBidiMarks = false; dataDir = dataDir + "Document.AddBidiMarks_out.txt"; doc.Save(dataDir, saveOptions); //ExEnd:AddBidiMarks Console.WriteLine("\nAdd bi-directional marks set successfully.\nFile saved at " + dataDir); }
public static void DefaultLevelForListIndentation(string dataDir) { //ExStart:DefaultLevelForListIndentation Document doc1 = new Document("input_document"); doc1.Save(dataDir + "output1.txt"); Document doc2 = new Document("input_document"); TxtSaveOptions options = new TxtSaveOptions(); doc2.Save(dataDir + "output2.txt", options); //ExEnd:DefaultLevelForListIndentation }
public static void UseSpaceCharacterPerLevelForListIndentation(string dataDir) { //ExStart:UseSpaceCharacterPerLevelForListIndentation Document doc = new Document("input_document"); TxtSaveOptions options = new TxtSaveOptions(); options.ListIndentation.Count = 3; options.ListIndentation.Character = ' '; doc.Save(dataDir + "output.txt", options); //ExEnd:UseSpaceCharacterPerLevelForListIndentation }
/// <summary>生成PDF文件</summary> public override bool Execute(string sourceFile, string pdfFile, string destFile) { var document = new Document(sourceFile); var options = new TxtSaveOptions(); options.Encoding = Encoding.UTF8; options.ExportHeadersFooters = false; options.ParagraphBreak = Environment.NewLine; options.PreserveTableLayout = false; options.SimplifyListLabels = true; document.Save(destFile, options); return(true); }
public void SimplifyListLabels(bool simplifyListLabels) { //ExStart //ExFor:TxtSaveOptions.SimplifyListLabels //ExSummary:Shows how to change the appearance of lists when saving a document to plaintext. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Create a bulleted list with five levels of indentation. builder.ListFormat.ApplyBulletDefault(); builder.Writeln("Item 1"); builder.ListFormat.ListIndent(); builder.Writeln("Item 2"); builder.ListFormat.ListIndent(); builder.Writeln("Item 3"); builder.ListFormat.ListIndent(); builder.Writeln("Item 4"); builder.ListFormat.ListIndent(); builder.Write("Item 5"); // Create a "TxtSaveOptions" object, which we can pass to the document's "Save" method // to modify how we save the document to plaintext. TxtSaveOptions txtSaveOptions = new TxtSaveOptions(); // Set the "SimplifyListLabels" property to "true" to convert some list // symbols into simpler ASCII characters, such as '*', 'o', '+', '>', etc. // Set the "SimplifyListLabels" property to "false" to preserve as many original list symbols as possible. txtSaveOptions.SimplifyListLabels = simplifyListLabels; doc.Save(ArtifactsDir + "TxtSaveOptions.SimplifyListLabels.txt", txtSaveOptions); string docText = File.ReadAllText(ArtifactsDir + "TxtSaveOptions.SimplifyListLabels.txt"); if (simplifyListLabels) { Assert.AreEqual("* Item 1\r\n" + " > Item 2\r\n" + " + Item 3\r\n" + " - Item 4\r\n" + " o Item 5\r\n", docText); } else { Assert.AreEqual("· Item 1\r\n" + "o Item 2\r\n" + "§ Item 3\r\n" + "· Item 4\r\n" + "o Item 5\r\n", docText); } //ExEnd }
public void AddBidiMarks() { //ExStart //ExFor:TxtSaveOptions.AddBidiMarks //ExSummary:Shows how to insert Unicode Character 'RIGHT-TO-LEFT MARK' (U+200F) before each bi-directional Run in text. Document doc = new Document(MyDir + "Document.docx"); TxtSaveOptions saveOptions = new TxtSaveOptions { AddBidiMarks = true }; doc.Save(ArtifactsDir + "AddBidiMarks.txt", saveOptions); //ExEnd }
/// <summary>生成PDF文件</summary> public override bool Execute(string sourceFile, string pdfFile, string destFile) { var workbook = new Workbook(sourceFile); var options = new TxtSaveOptions(); options.Encoding = Encoding.UTF8; //options.FormatStrategy = CellValueFormatStrategy.None; options.QuoteType = TxtValueQuoteType.Never; //options.TrimLeadingBlankRowAndColumn = true; workbook.Save(destFile, options); var content = File.ReadAllText(destFile); WriteFile(destFile, content, true); return(true); }
public void SimplifyListLabels(bool simplifyListLabels) { //ExStart //ExFor:TxtSaveOptions.SimplifyListLabels //ExSummary:Shows how to change the appearance of lists when converting to plaintext. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Create a bulleted list with five levels of indentation builder.ListFormat.ApplyBulletDefault(); builder.Writeln("Item 1"); builder.ListFormat.ListIndent(); builder.Writeln("Item 2"); builder.ListFormat.ListIndent(); builder.Writeln("Item 3"); builder.ListFormat.ListIndent(); builder.Writeln("Item 4"); builder.ListFormat.ListIndent(); builder.Write("Item 5"); // The SimplifyListLabels flag will convert some list symbols // into ASCII characters such as *, o, +, > etc, depending on list level TxtSaveOptions txtSaveOptions = new TxtSaveOptions { SimplifyListLabels = simplifyListLabels }; doc.Save(ArtifactsDir + "TxtSaveOptions.SimplifyListLabels.txt", txtSaveOptions); string docText = File.ReadAllText(ArtifactsDir + "TxtSaveOptions.SimplifyListLabels.txt"); if (simplifyListLabels) { Assert.AreEqual("* Item 1\r\n" + " > Item 2\r\n" + " + Item 3\r\n" + " - Item 4\r\n" + " o Item 5\r\n", docText); } else { Assert.AreEqual("· Item 1\r\n" + "o Item 2\r\n" + "§ Item 3\r\n" + "· Item 4\r\n" + "o Item 5\r\n", docText); } //ExEnd }
public void PreserveTableLayout(bool preserveTableLayout) { //ExStart //ExFor:TxtSaveOptions.PreserveTableLayout //ExSummary:Shows how to preserve the layout of tables when converting to plaintext. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.StartTable(); builder.InsertCell(); builder.Write("Row 1, cell 1"); builder.InsertCell(); builder.Write("Row 1, cell 2"); builder.EndRow(); builder.InsertCell(); builder.Write("Row 2, cell 1"); builder.InsertCell(); builder.Write("Row 2, cell 2"); builder.EndTable(); // Create a "TxtSaveOptions" object, which we can pass to the document's "Save" method // to modify how we save the document to plaintext. TxtSaveOptions txtSaveOptions = new TxtSaveOptions(); // Set the "PreserveTableLayout" property to "true" to apply whitespace padding to the contents // of the output plaintext document to preserve as much of the table's layout as possible. // Set the "PreserveTableLayout" property to "false" to save all tables' contents // as a continuous body of text, with just a new line for each row. txtSaveOptions.PreserveTableLayout = preserveTableLayout; doc.Save(ArtifactsDir + "TxtSaveOptions.PreserveTableLayout.txt", txtSaveOptions); string docText = File.ReadAllText(ArtifactsDir + "TxtSaveOptions.PreserveTableLayout.txt"); if (preserveTableLayout) { Assert.AreEqual("Row 1, cell 1 Row 1, cell 2\r\n" + "Row 2, cell 1 Row 2, cell 2\r\n\r\n", docText); } else { Assert.AreEqual("Row 1, cell 1\r\n" + "Row 1, cell 2\r\n" + "Row 2, cell 1\r\n" + "Row 2, cell 2\r\n\r\n", docText); } //ExEnd }
public void TableLayout(bool preserveTableLayout) { //ExStart //ExFor:TxtSaveOptions.PreserveTableLayout //ExSummary:Shows how to preserve the layout of tables when converting to plaintext. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Insert a table builder.StartTable(); builder.InsertCell(); builder.Write("Row 1, cell 1"); builder.InsertCell(); builder.Write("Row 1, cell 2"); builder.EndRow(); builder.InsertCell(); builder.Write("Row 2, cell 1"); builder.InsertCell(); builder.Write("Row 2, cell 2"); builder.EndTable(); // Tables, with their borders and widths do not translate to plaintext // However, we can configure a SaveOptions object to arrange table contents to preserve some of the table's appearance TxtSaveOptions txtSaveOptions = new TxtSaveOptions { PreserveTableLayout = preserveTableLayout }; doc.Save(ArtifactsDir + "TxtSaveOptions.TableLayout.txt", txtSaveOptions); string docText = File.ReadAllText(ArtifactsDir + "TxtSaveOptions.TableLayout.txt"); if (preserveTableLayout) { Assert.AreEqual("Row 1, cell 1 Row 1, cell 2\r\n" + "Row 2, cell 1 Row 2, cell 2\r\n\r\n", docText); } else { Assert.AreEqual("Row 1, cell 1\r\n" + "Row 1, cell 2\r\n" + "Row 2, cell 1\r\n" + "Row 2, cell 2\r\n\r\n", docText); } //ExEnd }
public void TxtListIndentation() { //ExStart //ExFor:TxtListIndentation //ExFor:TxtListIndentation.Count //ExFor:TxtListIndentation.Character //ExSummary:Shows how list levels are displayed when the document is converting to plain text format Document doc = new Document(MyDir + "TxtSaveOptions.TxtListIndentation.docx"); TxtSaveOptions txtSaveOptions = new TxtSaveOptions(); txtSaveOptions.ListIndentation.Count = 3; txtSaveOptions.ListIndentation.Character = ' '; txtSaveOptions.PreserveTableLayout = true; doc.Save(ArtifactsDir + "TxtSaveOptions.TxtListIndentation.txt", txtSaveOptions); //ExEnd }
public void AddBidiMarks() { //ExStart:AddBidiMarks Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("Hello world!"); builder.ParagraphFormat.Bidi = true; builder.Writeln("שלום עולם!"); builder.Writeln("مرحبا بالعالم!"); TxtSaveOptions saveOptions = new TxtSaveOptions { AddBidiMarks = true }; doc.Save(ArtifactsDir + "WorkingWithTxtSaveOptions.AddBidiMarks.txt", saveOptions); //ExEnd:AddBidiMarks }
public void MaxCharactersPerLine() { //ExStart //ExFor:TxtSaveOptions.MaxCharactersPerLine //ExSummary:Shows how to set maximum number of characters per line. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Write("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " + "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."); // Set 30 characters as maximum allowed per one line. TxtSaveOptions saveOptions = new TxtSaveOptions { MaxCharactersPerLine = 30 }; doc.Save(ArtifactsDir + "TxtSaveOptions.MaxCharactersPerLine.txt", saveOptions); //ExEnd }
public void PageBreaks(string resultText, bool isForcePageBreaks) { //ExStart //ExFor:TxtSaveOptions.ForcePageBreaks //ExSummary:Shows how to specify whether the page breaks should be preserved during export. Document doc = new Document(MyDir + "SaveOptions.PageBreaks.docx"); TxtSaveOptions saveOptions = new TxtSaveOptions { ForcePageBreaks = isForcePageBreaks }; doc.Save(MyDir + @"\Artifacts\SaveOptions.PageBreaks.txt", saveOptions); //ExEnd Document docFalse = new Document(MyDir + @"\Artifacts\SaveOptions.PageBreaks.txt"); Assert.AreEqual(resultText, docFalse.GetText()); }
public void ExportHeadersFooters(TxtExportHeadersFootersMode txtExportHeadersFootersMode) { //ExStart //ExFor:TxtSaveOptionsBase.ExportHeadersFootersMode //ExFor:TxtExportHeadersFootersMode //ExSummary:Shows how to specifies the way headers and footers are exported to plain text format. Document doc = new Document(MyDir + "HeaderFooter.HeaderFooterOrder.docx"); // Three values are available in TxtExportHeadersFootersMode enum: // "None" - No headers and footers are exported // "AllAtEnd" - All headers and footers are placed after all section bodies at the very end of a document // "PrimaryOnly" - Only primary headers and footers are exported at the beginning and end of each section (default value) TxtSaveOptions saveOptions = new TxtSaveOptions { ExportHeadersFootersMode = txtExportHeadersFootersMode }; doc.Save(ArtifactsDir + "ExportHeadersFooters.txt", saveOptions); //ExEnd }
public void Encoding() { //ExStart //ExFor:TxtSaveOptionsBase.Encoding //ExSummary:Shows how to set encoding for a .txt output document. // Create a new document and add some text from outside the ASCII character set Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("À È Ì Ò Ù."); // We can use a SaveOptions object to make sure the encoding we save the .txt document in supports our content TxtSaveOptions txtSaveOptions = new TxtSaveOptions { Encoding = System.Text.Encoding.UTF8 }; doc.Save(ArtifactsDir + "TxtSaveOptions.Encoding.txt", txtSaveOptions); //ExEnd }
public static void Run() { // ExStart:1 // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Load your source workbook Workbook workbook = new Workbook(dataDir + "book1.xls"); //0-byte array byte[] workbookData = new byte[0]; // Text save options. You can use any type of separator TxtSaveOptions opts = new TxtSaveOptions(); opts.Separator = '\t'; // Copy each worksheet data in text format inside workbook data array for (int idx = 0; idx < workbook.Worksheets.Count; idx++) { // Save the active worksheet into text format MemoryStream ms = new MemoryStream(); workbook.Worksheets.ActiveSheetIndex = idx; workbook.Save(ms, opts); // Save the worksheet data into sheet data array ms.Position = 0; byte[] sheetData = ms.ToArray(); // Combine this worksheet data into workbook data array byte[] combinedArray = new byte[workbookData.Length + sheetData.Length]; Array.Copy(workbookData, 0, combinedArray, 0, workbookData.Length); Array.Copy(sheetData, 0, combinedArray, workbookData.Length, sheetData.Length); workbookData = combinedArray; } // Save entire workbook data into file File.WriteAllBytes(dataDir + "out.txt", workbookData); // ExEnd:1 }
public void PageBreaks() { Document doc = new Document(MyDir + "SaveOptions.PageBreaks.docx"); TxtSaveOptions saveOptions = new TxtSaveOptions(); saveOptions.ForcePageBreaks = false; doc.Save(MyDir + @"\Artifacts\SaveOptions.PageBreaks False Out.txt", saveOptions); Document docFalse = new Document(MyDir + @"\Artifacts\SaveOptions.PageBreaks False Out.txt"); Assert.AreEqual("Some text before page break\r\rJidqwjidqwojidqwojidqwojidqwojidqwoji\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\rQwdqwdqwdqwdqwdqwdqwd\rQwdqwdqwdqwdqwdqwdqw\r\r\r\r\rqwdqwdqwdqwdqwdqwdqwqwd\r\f", docFalse.GetText()); saveOptions.ForcePageBreaks = true; doc.Save(MyDir + @"\Artifacts\SaveOptions.PageBreaks True Out.txt", saveOptions); Document docTrue = new Document(MyDir + @"\Artifacts\SaveOptions.PageBreaks True Out.txt"); Assert.AreEqual("Some text before page break\r\f\r\fJidqwjidqwojidqwojidqwojidqwojidqwoji\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\rQwdqwdqwdqwdqwdqwdqwd\rQwdqwdqwdqwdqwdqwdqw\r\r\r\r\f\r\fqwdqwdqwdqwdqwdqwdqwqwd\r\f", docTrue.GetText()); }
public static void Run() { // ExStart:1 // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Load your source workbook Workbook workbook = new Workbook(dataDir + "book1.xls"); //0-byte array byte[] workbookData = new byte[0]; // Text save options. You can use any type of separator TxtSaveOptions opts = new TxtSaveOptions(); opts.Separator = '\t'; // Copy each worksheet data in text format inside workbook data array for (int idx = 0; idx < workbook.Worksheets.Count; idx++) { // Save the active worksheet into text format MemoryStream ms = new MemoryStream(); workbook.Worksheets.ActiveSheetIndex = idx; workbook.Save(ms, opts); // Save the worksheet data into sheet data array ms.Position = 0; byte[] sheetData = ms.ToArray(); // Combine this worksheet data into workbook data array byte[] combinedArray = new byte[workbookData.Length + sheetData.Length]; Array.Copy(workbookData, 0, combinedArray, 0, workbookData.Length); Array.Copy(sheetData, 0, combinedArray, workbookData.Length, sheetData.Length); workbookData = combinedArray; } // Save entire workbook data into file File.WriteAllBytes(dataDir + "out.txt", workbookData); // ExEnd:1 }
public void AddBidiMarks(bool addBidiMarks) { //ExStart //ExFor:TxtSaveOptions.AddBidiMarks //ExSummary:Shows how to insert Unicode Character 'RIGHT-TO-LEFT MARK' (U+200F) before each bi-directional Run in text. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("Hello world!"); builder.ParagraphFormat.Bidi = true; builder.Writeln("שלום עולם!"); builder.Writeln("مرحبا بالعالم!"); // Create a "TxtSaveOptions" object, which we can pass to the document's "Save" method // to modify how we save the document to plaintext. TxtSaveOptions saveOptions = new TxtSaveOptions { Encoding = System.Text.Encoding.Unicode }; // Set the "AddBidiMarks" property to "true" to add marks before runs // with right-to-left text to indicate the fact. // Set the "AddBidiMarks" property to "false" to write all left-to-right // and right-to-left run equally with nothing to indicate which is which. saveOptions.AddBidiMarks = addBidiMarks; doc.Save(ArtifactsDir + "TxtSaveOptions.AddBidiMarks.txt", saveOptions); string docText = System.Text.Encoding.Unicode.GetString(File.ReadAllBytes(ArtifactsDir + "TxtSaveOptions.AddBidiMarks.txt")); if (addBidiMarks) { Assert.AreEqual("\uFEFFHello world!\r\nשלום עולם!\r\nمرحبا بالعالم!\r\n\r\n", docText); Assert.True(docText.Contains("\u200f")); } else { Assert.AreEqual("\uFEFFHello world!\r\nשלום עולם!\r\nمرحبا بالعالم!\r\n\r\n", docText); Assert.False(docText.Contains("\u200f")); } //ExEnd }
public void Appearance() { //ExStart //ExFor:TxtSaveOptionsBase.PreserveTableLayout //ExFor:TxtSaveOptions.SimplifyListLabels //ExSummary:Shows how to change the appearance of tables and lists during conversion to a txt document output. // Open a document with a table Document doc = new Document(MyDir + "Lists.PrintOutAllLists.doc"); // Due to the nature of text documents, table grids and text wrapping will be lost during conversion // from a file type that supports tables // We can preserve some of the table layout in the appearance of our content with the PreserveTableLayout flag // The SimplifyListLabels flag will convert some list symbols // into ASCII characters such as *, o, +, > etc, depending on list level TxtSaveOptions txtSaveOptions = new TxtSaveOptions { SimplifyListLabels = true, PreserveTableLayout = true }; doc.Save(ArtifactsDir + "TxtSaveOptions.Appearance.txt", txtSaveOptions); //ExEnd }
public static void Main(string[] args) { //ExStart:1 // The path to the documents directory. string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); string filePath = dataDir + "Book1.xlsx"; //Create a Workbook object and opening the file from its path Workbook wb = new Workbook(filePath); //Instantiate Text File's Save Options TxtSaveOptions options = new TxtSaveOptions(); //Specify the separator options.Separator = Convert.ToChar(";"); //Save the file with the options wb.Save(dataDir + "output.csv", options); //ExEnd:1 }
static void Main(string[] args) { string FilePath = @"..\..\..\Sample Files\"; string FileName = FilePath + "Save Workbook to Text or CSV Format.xlsx"; string destFileName = FilePath + "Save Workbook to Text or CSV Format.txt"; //Load your source workbook Workbook workbook = new Workbook(FileName); //0-byte array byte[] workbookData = new byte[0]; //Text save options. You can use any type of separator TxtSaveOptions opts = new TxtSaveOptions(); opts.Separator = '\t'; //Copy each worksheet data in text format inside workbook data array for (int idx = 0; idx < workbook.Worksheets.Count; idx++) { //Save the active worksheet into text format MemoryStream ms = new MemoryStream(); workbook.Worksheets.ActiveSheetIndex = idx; workbook.Save(ms, opts); //Save the worksheet data into sheet data array ms.Position = 0; byte[] sheetData = ms.ToArray(); //Combine this worksheet data into workbook data array byte[] combinedArray = new byte[workbookData.Length + sheetData.Length]; Array.Copy(workbookData, 0, combinedArray, 0, workbookData.Length); Array.Copy(sheetData, 0, combinedArray, workbookData.Length, sheetData.Length); workbookData = combinedArray; } //Save entire workbook data into file File.WriteAllBytes(destFileName, workbookData); }
public static void Run() { // ExStart:1 // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); string filePath = dataDir + "Book1.xlsx"; // Create a Workbook object and opening the file from its path Workbook wb = new Workbook(filePath); // Instantiate Text File's Save Options TxtSaveOptions options = new TxtSaveOptions(); // Specify the separator options.Separator = Convert.ToChar(";"); // Save the file with the options wb.Save(dataDir + "output.csv", options); // ExEnd:1 }
public static bool ExportCSV(DataTable dt, string path) { bool succeed = false; if (dt != null) { try { Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(); Aspose.Cells.Worksheet cellSheet = workbook.Worksheets[0]; int rowIndex = 0; int colIndex = 0; int colCount = dt.Columns.Count; int rowCount = dt.Rows.Count; for (int i = 0; i < rowCount; i++) { colIndex = 0; for (int j = 0; j < colCount; j++) { cellSheet.Cells[rowIndex, colIndex].PutValue(dt.Rows[i][j].ToString()); colIndex++; } rowIndex++; } //0-byte array byte[] workbookData = new byte[0]; //Text save options. You can use any type of separator TxtSaveOptions opts = new TxtSaveOptions(); opts.Separator = '\t'; opts.Encoding = System.Text.Encoding.Default; //Copy each worksheet data in text format inside workbook data array for (int idx = 0; idx < workbook.Worksheets.Count; idx++) { //Save the active worksheet into text format MemoryStream ms = new MemoryStream(); workbook.Worksheets.ActiveSheetIndex = idx; workbook.Save(ms, opts); //Save the worksheet data into sheet data array ms.Position = 0; byte[] sheetData = ms.ToArray(); //Combine this worksheet data into workbook data array byte[] combinedArray = new byte[workbookData.Length + sheetData.Length]; Array.Copy(workbookData, 0, combinedArray, 0, workbookData.Length); Array.Copy(sheetData, 0, combinedArray, workbookData.Length, sheetData.Length); workbookData = combinedArray; } //cellSheet.AutoFitColumns(); path = Path.GetFullPath(path); //Save entire workbook data into file File.WriteAllBytes(path, workbookData); //workbook.Save(path,SaveFormat.CSV); succeed = true; } catch (Exception ex) { succeed = false; } } return succeed; }