we just bought Aspose.Cells and we just want to extract the content of excel files into a string variable. i already tried to find the right methods and procedures but without access. might be the case that i have overseen something, then i am sorry.
What do you mean by extract the content of excel files into a string variable? Well, if you want to get a cell value into a string variable, you may use Cell.StringValue attribute. If you need to export the contents of a complete sheet, you may utilize Cells.ExportArray() / ExportDataTable to fill an array / datatable for your need.
thank you very much for your answer. I could already succeed with reading the content of particular cells into a string variable. But I could not with the entire sheet. What I need is to get the text of all the cells in a string array. As you wrote with Cells.ExportArray I could not realize it. It would be really nice if you couls help me further.
Cells.ExportArray() method returns a 2-Dimensional Object type Array (Rows & Columns as dimension). You can iterate through this exported array and create your own one dimensional string array . please see the sample code which will help you in getting your desired results
Sample Code:-
Workbook workbook = new Workbook();
workbook.Open("F:\\Excels\\Book1.xls");
Worksheet worksheet = workbook.Worksheets[0];
object[,] arr = worksheet.Cells.ExportArray(0, 0, worksheet.Cells.MaxRow + 1, worksheet.Cells.MaxColumn + 1);
string[] array = new string[worksheet.Cells.MaxRow * worksheet.Cells.MaxColumn];
int count =0;
for (int row = 0; row < worksheet.Cells.MaxRow; row++)
{
for (int col = 0; col < worksheet.Cells.MaxColumn; col++)
{
if (arr.GetValue(row, col) != null)
{
array[count] = arr.GetValue(row, col).ToString();
}
count += 1;
}
}
Thank you & Best Regards,
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.