Unable to get value from Excel file

Jun 30, 2009 at 11:26 PM
Edited Jun 30, 2009 at 11:35 PM

I have an InfoPath form with a File Attachment control, the value return by the File Attachment control is a 64-based string, the value is not a Excel file path.

Thus, I couldn't find a way to push the value into FileStream, but I tried to push the value into MemoryStream. My code as below:

string content = // value returned from File Attachment control
bytes[] contentBytes = Convert.FromBase64String(content);
// This contentBytes not only contains the data in Excel file,
// also the file name, file size, etc.
bytes[] dataBytes = // get the bytes[] of only the data in Excel file
MemoryStream stream = new MemoryStream(dataBytes);

// The attached Excel is .xls file
IExcelDataReader reader = Factory.CreateReader(stream, ExcelFileType.Binary);
DataSet ds = reader.AsDataSet();

    // ** reader.GetString(index) returns empty value;

DataTable dt = ds.Tables[0];
DataRowCollection rows = dt.Rows;
for(int i = 0; i < rows.Count; i++)
    foreach(DataColumn column in dt.Columns)
        // ** rows[i][column.Ordinal] returns empty value;

Where do I did incorrectly?

Please advice, thanks.

Jul 2, 2009 at 7:54 AM


Just would like to share my experience, I couldn't read my excel is because I have chinese font-family in my excel file. It's working fine after I've changed the font-family to Arial. Anyway, how to make this excel reader understand chinese font type. And also, I have a column contains date value, but seems this excel reader doesn't understand date format data.