我有一个应该使用以下代码块解析的 excel 文档:
var handler = new ExcelHandler(byteStream);
var currentExcelDocument = handler.CurrentDocument;
//now if the document is null
if (currentExcelDocument == null)
{
throw new Exception("Excel file handle missing");
}
var wokrbookpart = currentExcelDocument.WorkbookPart;
//get a list of all the sheets
string text = String.Empty;
var sheets = wokrbookpart.Workbook.Descendants<Sheet>().ToList();
foreach (var sh in sheets)
{
//now we have the sheets but the data must be in the first sheet
var themainsheet = sh;
if (themainsheet == null)
throw new ArgumentException("sheetName");
//now we need a reference to the worksheetpart
var worksheetpart = (WorksheetPart)wokrbookpart.GetPartById(themainsheet.Id);
SheetData data = worksheetpart.Worksheet.Elements<SheetData>().First();
//now we have a reference to the cells that contain data we start passing the data
foreach (Row r in data.Elements<Row>())
{
//we get the cells in the row
var cells = r.Elements<Cell>().ToList();
foreach (var i in cells)
{
text += i.CellValue.InnerText;
}
}
}
return text;
excel文件通过asp.net中的fileupload控件上传,流被传递到上面的代码块中。
一切都很好,但是当我在标签中显示结果文本时,我看到读取单元格值的结果显示为一系列数字,即使我确信数据中没有数字
请问我做错了什么?