We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to get the content of an excel file into a string variable

hello support team,

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.

Please give me feedback - thank you



Hi Julian,

Thanks for your inquiry.

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.

Check the following docs for your reference:



Kindly let us know if you need further assistance, we will be happy to help you.

Thank you.

Hi again,

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.


Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.

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();


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,