I am trying to extract TEXT from a .xlsx
Excel file using NPOI.
Below is the link of sample Excel file:
http://s29.postimg.org/i7rtrucaf/excel_File.png
The function ExcelDocumentToText
extracts all the cell values, but not the cell which contains INR (cell F2)
static void ExcelDocumentToText(string path = @"..\..\..\01.xlsx")
{
StringBuilder textOfExcelDocumnet = new StringBuilder();
ISheet sheet = null; IRow headerRow = null; IEnumerator allRows = null;
using (FileStream ExcelFile = new FileStream(path, FileMode.Open, FileAccess.Read))
xlsReaderObject = new XSSFWorkbook(ExcelFile);
for (int j = 0; j < xlsReaderObject.Count; j++)
{
sheet = xlsReaderObject.GetSheetAt(j);
for (int p = 0; p < sheet.LastRowNum; p++)
{
headerRow = sheet.GetRow(p);
if (headerRow != null)
break;
}
allRows = sheet.GetRowEnumerator();
int colCount = headerRow.LastCellNum;
while (allRows.MoveNext())
{
//IRow row = (HSSFRow)rows.Current;
IRow row = (XSSFRow)allRows.Current;
for (int i = 0; i < colCount; i++)
{
ICell cell = row.GetCell(i);
if (cell != null)
textOfExcelDocumnet.AppendLine(cell.ToString());
}
}
sheet = null; headerRow = null; allRows = null;
}
xlsReaderObject = null;
Console.WriteLine(textOfExcelDocumnet.ToString());
}
Could anyone please have some solution of this query?