I have a text file in tab-delimited format. Some cells are represented like this: =“04”, since the leading zeroes are important to my app.
I would like to open this text file in Aspose.Excel, copy all the cells and paste-as-value so the leading characters are preserved, then save this as an Excel spreadsheet that can open in Excel and still preserve the leading zeroes.
In “normal” Excel VBA I can select a range of cells, like:
ActiveSheet.Cells.Copy()
ActiveSheet.Cells.PasteSpecial(Excel.xlPasteType.xlPasteValue)
and then save the sheet
Is there a way that Aspose.Excel can do that also?
Hi, thanks for your consideration.
You can use your own code to load the content of your text file to a string array or a datatable, then you can use Cells.ImportArray or Cells.ImportDataTable method to import the values.
@a2brute,
Aspose.Cells has replaced Aspose.Excel which is discontinued now. Aspose.Cells contains exciting new features and supports all the versions of MS Excel features. Data can be imported into worksheet with a variety of ways using this upgraded library as well. You may try the following sample code to import data into worksheet:
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Obtaining the reference of the worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Creating an array containing names as string values
string[] names = new string[] { "laurence chen", "roman korchagin", "kyle huang" };
// Importing the array of names to 1st row and first column vertically
worksheet.Cells.ImportArray(names, 0, 0, true);
// Saving the Excel file
workbook.Save(dataDir + "DataImport.out.xls");
For more information on opening different versions of Excel files, please follow the link below:
Import Data into Worksheet
Download the latest version of Aspose.Cells for .NET from the following link:
Aspose.Cells for .NET (Latest Version)
You can download the latest demos here.