



User Guide EasyXLS Basics Export files Export to TXT file in .NET, Java and other programming languages Tweet Export to TXT file in .NET, Java and other programming languages Concept EasyXLS™ library allows you to export data to text file format and specify the separators for data in rows and columns.



EasyXLS can be successfully used inclusively to export large TXT files having big volume of data with fast exporting time. Concept in action



The source code samples can be integrated in:

- ASP.NET web pages

- Windows applications

- Windows Forms (WinForms)

- Console applications

- Windows service applications

- ASP.NET MVC web applications

- PHP and ASP web pages

- Java applications The below example shows how to export data to text file.The source code samples can be integrated in: Source code sample C#.NET VB.NET C++.NET J#.NET Java PHP ASP C++ VB6 VBS Coldfusion // Create an instance of the class that exports Excel files, having a sheet ExcelDocument workbook = new ExcelDocument(1); // Set the sheet name workbook.easy_getSheetAt(0).setSheetName("First tab"); // Get the table of data for the worksheet ExcelTable xlsFirstTable = ((ExcelWorksheet)workbook.easy_getSheetAt(0)).easy_getExcelTable(); // Add data in cells for report header for (int column=0; column<5; column++) { xlsFirstTable.easy_getCell(0,column).setValue("Column " + (column + 1)); xlsFirstTable.easy_getCell(0,column).setDataType(DataType.STRING); } // Add data in cells for report values for (int row=0; row<100; row++) { for (int column=0; column<5; column++) { xlsFirstTable.easy_getCell(row+1,column).setValue( "Data " + (row + 1) + ", " + (column + 1)); xlsFirstTable.easy_getCell(row+1,column).setDataType(DataType.STRING); } } // Export text file workbook.easy_WriteTXTFile("C:\\Samples\\Export to text file.txt", "First tab", "\r

", "\t"); ' Create an instance of the class that exports Excel files, having a sheet Dim workbook As New ExcelDocument(1) ' Set the sheet name workbook.easy_getSheetAt(0).setSheetName("First tab") ' Get the table of data for the worksheet Dim xlsFirstTab As ExcelWorksheet = workbook.easy_getSheetAt(0) Dim xlsFirstTable = xlsFirstTab.easy_getExcelTable() ' Add data in cells for report header For column As Integer = 0 To 4 xlsFirstTable.easy_getCell(0, column).setValue("Column " & (column + 1)) xlsFirstTable.easy_getCell(0, column).setDataType(DataType.STRING) Next ' Add data in cells for report values For row As Integer = 0 To 99 For column As Integer = 0 To 4 xlsFirstTable.easy_getCell(row + 1, column).setValue( _ "Data " & (row + 1) & ", " & (column + 1)) xlsFirstTable.easy_getCell(row + 1, column).setDataType(DataType.STRING) Next Next ' Export text file workbook.easy_WriteTXTFile("C:\Samples\Export to text file.txt", _ "First tab", "\r

", "\t") // Create an instance of the class that exports Excel files, having a sheet ExcelDocument *workbook = new ExcelDocument(1); // Set the sheet name workbook->easy_getSheetAt(0)->setSheetName("First tab"); // Get the table of data for the worksheet ExcelWorksheet *xlsFirstTab = __try_cast<ExcelWorksheet*>(workbook->easy_getSheetAt(0)); ExcelTable *xlsFirstTable = xlsFirstTab->easy_getExcelTable(); // Add data in cells for report header for (int column=0; column<5; column++) { xlsFirstTable->easy_getCell(0,column)->setValue( String::Concat("Column ",(column + 1).ToString())); xlsFirstTable->easy_getCell(0,column)->setDataType(DataType::STRING); } // Add data in cells for report values for (int row=0; row<100; row++) { for (int column=0; column<5; column++) { xlsFirstTable->easy_getCell(row+1,column)->setValue(String::Concat( "Data ", (row + 1).ToString(), ", ", (column + 1).ToString())); xlsFirstTable->easy_getCell(row+1,column)->setDataType(DataType::STRING); } } // Export text file workbook->easy_WriteTXTFile("C:\\Samples\\Export to text file.txt", "First tab", "\r

", "\t"); // Create an instance of the class that exports Excel files, having a sheet ExcelDocument workbook = new ExcelDocument(1); // Set the sheet name workbook.easy_getSheetAt(0).setSheetName("First tab"); // Get the table of data for the worksheet ExcelTable xlsFirstTable = ((ExcelWorksheet)workbook.easy_getSheetAt(0)).easy_getExcelTable(); // Add data in cells for report header for (int column=0; column<5; column++) { xlsFirstTable.easy_getCell(0,column).setValue("Column " + (column + 1)); xlsFirstTable.easy_getCell(0,column).setDataType(DataType.STRING); } // Add data in cells for report values for (int row=0; row<100; row++) { for (int column=0; column<5; column++) { xlsFirstTable.easy_getCell(row+1,column).setValue( "Data " + (row + 1) + ", " + (column + 1)); xlsFirstTable.easy_getCell(row+1,column).setDataType(DataType.STRING); } } // Export text file workbook.easy_WriteTXTFile("C:\\Samples\\Export to text file.txt", "First tab", "\r

", "\t"); // Create an instance of the class that exports Excel files, having a sheet ExcelDocument workbook = new ExcelDocument(1); // Set the sheet name workbook.easy_getSheetAt(0).setSheetName("First tab"); // Get the table of data for the worksheet ExcelTable xlsFirstTable = ((ExcelWorksheet)workbook.easy_getSheetAt(0)).easy_getExcelTable(); // Add data in cells for report header for (int column=0; column<5; column++) { xlsFirstTable.easy_getCell(0,column).setValue("Column " + (column + 1)); xlsFirstTable.easy_getCell(0,column).setDataType(DataType.STRING); } // Add data in cells for report values for (int row=0; row<100; row++) { for (int column=0; column<5; column++) { xlsFirstTable.easy_getCell(row+1,column).setValue( "Data " + (row + 1) + ", " + (column + 1)); xlsFirstTable.easy_getCell(row+1,column).setDataType(DataType.STRING); } } // Export text file workbook.easy_WriteTXTFile("C:\\Samples\\Export to text file.txt", "First tab", "\r

", "\t"); // Create an instance of the class that exports Excel files $workbook = new COM("EasyXLS.ExcelDocument"); // Create a worksheet $workbook->easy_addWorksheet_2("First tab"); // Get the table of data for the worksheet $xlsFirstTable = $workbook->easy_getSheetAt(0)->easy_getExcelTable(); // Add data in cells for report header for ($column=0; $column<5; $column++) { $xlsFirstTable->easy_getCell(0,$column)->setValue("Column " . ($column + 1)); $xlsFirstTable->easy_getCell(0,$column)->setDataType($DATATYPE_STRING); } // Add data in cells for report values for ($row=0; $row<100; $row++) { for ($column=0; $column<5; $column++) { $xlsFirstTable->easy_getCell($row+1,$column)->setValue( "Data ".($row + 1).", ".($column + 1)); $xlsFirstTable->easy_getCell($row+1,$column)->setDataType($DATATYPE_STRING); } } // Export text file $workbook->easy_WriteTXTFile("C:\Samples\Export to text file.txt", "First tab", "\r

", "\t"); ' Create an instance of the class that exports Excel files set workbook = Server.CreateObject("EasyXLS.ExcelDocument") ' Create a worksheet workbook.easy_addWorksheet_2("First tab") ' Get the table of data for the worksheet Set xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable() ' Add data in cells for report header for column = 0 to 4 xlsFirstTable.easy_getCell(0,column).setValue("Column " & (column + 1)) xlsFirstTable.easy_getCell(0,column).setDataType(DATATYPE_STRING) next ' Add data in cells for report values for row = 0 to 99 for column = 0 to 4 xlsFirstTable.easy_getCell(row+1,column).setValue( _ "Data " & (row + 1) & ", " & (column + 1)) xlsFirstTable.easy_getCell(row+1,column).setDataType(DATATYPE_STRING) next next ' Export text file workbook.easy_WriteTXTFile "C:\Samples\Export to text file.txt", "First tab", "\r

", "\t" // Create an instance of the class that exports Excel files EasyXLS::IExcelDocumentPtr workbook; hr = CoCreateInstance(__uuidof(EasyXLS::ExcelDocument), NULL, CLSCTX_ALL, __uuidof(EasyXLS::IExcelDocument), (void**) &workbook) ; // Create a worksheet workbook->easy_addWorksheet_2("First tab"); // Get the table of data for the worksheet EasyXLS::IExcelWorksheetPtr xlsFirstTab = (EasyXLS::IExcelWorksheetPtr)workbook->easy_getSheetAt(0); EasyXLS::IExcelTablePtr xlsFirstTable = xlsFirstTab->easy_getExcelTable(); // Add data in cells for report header char* cellValue = (char*)malloc(11*sizeof(char)); char* columnNumber = (char*)malloc(sizeof(char)); for (int column=0; column<5; column++) { strcpy(cellValue, "Column "); _itoa(column+ 1, columnNumber , 10); xlsFirstTable->easy_getCell(0,column)->setValue(strcat(cellValue, columnNumber)); xlsFirstTable->easy_getCell(0,column)->setDataType(DATATYPE_STRING); } // // Add data in cells for report values char* rowNumber = (char*)malloc(sizeof(char)); for (int row=0; row<100; row++) { for (int column=0; column<5; column++) { strcpy(cellValue, "Data "); _itoa(column+ 1, columnNumber , 10); _itoa(row + 1, rowNumber , 10); strcat(cellValue, rowNumber); strcat(cellValue, ", "); strcat(cellValue, columnNumber); xlsFirstTable->easy_getCell(row+1,column)->setValue(cellValue); xlsFirstTable->easy_getCell(row+1,column)->setDataType(DATATYPE_STRING); } } // Export text file workbook->easy_WriteTXTFile("C:\\Samples\\Export to text file.txt", "First tab", "\r

", "\t"); ' Create an instance of the class that exports Excel files Set workbook = CreateObject("EasyXLS.ExcelDocument") ' Create a worksheet workbook.easy_addWorksheet_2 ("First tab") ' Get the table of data for the worksheet Set xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable() ' Add data in cells for report header For column = 0 To 4 xlsFirstTable.easy_getCell(0, column).setValue ("column " & (column + 1)) xlsFirstTable.easy_getCell(0, column).setDataType (DataType.DATATYPE_STRING) Next ' Add data in cells for report values For row = 0 To 99 For column = 0 To 4 xlsFirstTable.easy_getCell(row + 1, column).setValue ( _ "Data " & (row + 1) & ", " & (column + 1)) xlsFirstTable.easy_getCell(row + 1, column).setDataType ( _ DataType.DATATYPE_STRING) Next Next ' Export text file workbook.easy_WriteTXTFile "C:\Samples\Export to text file.txt", _ "First tab", "\r

", "\t" ' Create an instance of the class that exports Excel files Set workbook = CreateObject("EasyXLS.ExcelDocument") ' Create a worksheet workbook.easy_addWorksheet_2("First tab") ' Get the table of data for the worksheet Set xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable() ' Add data in cells for report header For column = 0 To 4 xlsFirstTable.easy_getCell(0,column).setValue("column " & (column + 1)) xlsFirstTable.easy_getCell(0,column).setDataType(DATATYPE_STRING) Next ' Add data in cells for report values For row = 0 To 99 For column = 0 To 4 xlsFirstTable.easy_getCell(row+1,column).setValue( _ "Data " & (row + 1) & ", " & (column + 1)) xlsFirstTable.easy_getCell(row+1,column).setDataType(DATATYPE_STRING) Next Next ' Export text file workbook.easy_WriteTXTFile "C:\Samples\Export to text file.txt", _ "First tab", "\r

", "\t" <!-- Create an instance of the class that exports Excel files --> <cfobject type="java" class="EasyXLS.ExcelDocument" name="workbook" action="CREATE"> <!-- Create a worksheet --> <cfset ret = workbook.easy_addWorksheet("First tab")> <!-- Get the table of data for the worksheet --> <cfset xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()> <!-- Add data in cells for report header --> <cfloop from="0" to="4" index="column"> <cfset xlsFirstTable.easy_getCell(0,evaluate(column)).setValue( "Column " & evaluate(column + 1))> <cfset xlsFirstTable.easy_getCell(0,evaluate(column)).setDataType( DataType.STRING)> </cfloop> <!-- Add data in cells for report values --> <cfloop from="0" to="99" index="row"> <cfloop from="0" to="4" index="column"> <cfset xlsFirstTable.easy_getCell( evaluate(row + 1),evaluate(column)).setValue( "Data " & evaluate(row + 1) & ", " & evaluate(column + 1))> <cfset xlsFirstTable.easy_getCell(evaluate(row + 1), evaluate(column)).setDataType(DataType.STRING)> </cfloop> </cfloop> <!-- Export text file --> <cfset ret = workbook.easy_WriteTXTFile("C:\Samples\Export to text file.txt", "First tab", "\r

", "\t")> Export to text file with encoding EasyXLS allows you to export TXT files with specific encoding using System.IO.StreamWriter class in .NET and java.io.OutputStreamWriter class in Java with ExcelDocument.easy_WriteTXTFile method.



Export DataTable to TXT in C# and VB.NET EasyXLS allows exporting DataTable to TXT file. The DataTable can be inserted using ExcelWorksheet.easy_insertDataSet method and the TXT file must be exported using ExcelDocument.easy_WriteTXTFile method.

See also: Export GridView to TXT in C# and VB.NET from ASP.NET EasyXLS allows exporting GridView to TXT file. The DataTable of the GridView can be inserted using ExcelWorksheet.easy_insertDataSet method and the TXT file must be exported using ExcelDocument.easy_WriteTXTFile method.

See also: Export DataGridView to TXT in C# and VB.NET EasyXLS allows exporting DataGridView to TXT file. The DataTable of the DataGridView can be inserted using ExcelWorksheet.easy_insertDataSet method and the TXT file must be exported using ExcelDocument.easy_WriteTXTFile method.

See also: Export DataSet to TXT in C# and VB.NET EasyXLS allows exporting DataSet to TXT file. The DataSet can be inserted using ExcelWorksheet.easy_insertDataSet method and the TXT file must be exported using ExcelDocument.easy_WriteTXTFile method.

See also: Export ResultSet to TXT in Java EasyXLS allows exporting ResultSet to TXT file. The ResultSet can be inserted using ExcelWorksheet.easy_insertResultSet method and the TXT file must be exported using ExcelDocument.easy_WriteTXTFile method.

See also: Export list to text file EasyXLS allows exporting list to TXT file. The list can be inserted using ExcelWorksheet.easy_insertList method and the TXT file must be exported using ExcelDocument.easy_WriteTXTFile method.

See also: Export DataGrid to TXT in C# and VB.NET EasyXLS allows exporting DataGrid to TXT file. The DataTable of the DataGrid can be inserted using ExcelWorksheet.easy_insertDataSet method and the TXT file must be exported using ExcelDocument.easy_WriteTXTFile method.

See also: Export data to CSV file EasyXLS allows you to export data to CSV file.



See also: Getting started with EasyXLS Excel library To download the trial version of EasyXLS Excel Library, press the below button:





If you already own a license key, you may login and download EasyXLS from your account.



See also:

Related methods:

Available for: Professional, Excel Writer