被更多人找到了...... google ing ... 2007 年使用的第一行(xlsx
)
第二行是xls
版本
Net.SourceForge.Koogra.IWorkbook genericWB = Net.SourceForge.Koogra.WorkbookFactory.GetExcel2007Reader("tst.xlsx");
//genericWB = Net.SourceForge.Koogra.WorkbookFactory.GetExcelBIFFReader("some.xls");
Net.SourceForge.Koogra.IWorksheet genericWS = genericWB.Worksheets.GetWorksheetByIndex(0);
for (uint r = genericWS.FirstRow; r <= genericWS.LastRow; ++r)
{
Net.SourceForge.Koogra.IRow row = genericWS.Rows.GetRow(r);
for (uint c = genericWS.FirstCol; c <= genericWS.LastCol; ++c)
{
// raw value
Console.WriteLine(row.GetCell(c).Value);
// formatted value
Console.WriteLine(row.GetCell(c).GetFormattedValue());
}
}
我希望我能帮助遇到同样“内存不足”问题的其他人......'享受
对上面代码的一个小更新
好的..我已经玩了一点,就它与图表排名所依据的文件内容有关Unique IP
,当前代码是
//place source file within your current:
//project directory\bin\debug and you should find extracted file next to the source file
var pathtoRead = Path.Combine(Environment.CurrentDirectory, "tst.xlsx");
var pathtoWrite = Path.Combine(Environment.CurrentDirectory, "tst.txt");
Net.SourceForge.Koogra.IWorkbook genericWB = Net.SourceForge.Koogra.WorkbookFactory.GetExcel2007Reader(pathtoRead);
Net.SourceForge.Koogra.IWorksheet genericWS = genericWB.Worksheets.GetWorksheetByIndex(0);
StringBuilder SbXls = new StringBuilder();
for (uint r = genericWS.FirstRow; r <= genericWS.LastRow; ++r)
{
Net.SourceForge.Koogra.IRow row = genericWS.Rows.GetRow(r);
string LineEnding = string.Empty;
for (uint ColCount = genericWS.FirstCol; ColCount <= genericWS.LastCol; ++ColCount)
{
var formated = row.GetCell(ColCount).GetFormattedValue();
if (ColCount == 1)
LineEnding = Environment.NewLine;
else if (ColCount == 0)
LineEnding = "\t";
if (ColCount > 1 == false)
SbXls.Append(string.Concat(formated, LineEnding));
}
}
File.WriteAllText(pathtoWrite, SbXls.ToString());