1.读EXCEL
FileStream fs = new FileStream("C:\xx.xlsx", FileMode.Open, FileAccess.Read);
IWorkbook workbook = new XSSFWorkbook(fs);
fs.Dispose();
ISheet sheet = workbook.GetSheetAt(0);
int rowCount = sheet.LastRowNum;
for(int i = 0; i <= rowCount; i++)
{
IRow row = sheet.GetRow(i);
if (row == null) continue;
string sect1 = Convert.ToString(row.GetCell(0));
string sect2 = Convert.ToString(row.GetCell(1));
string sect3 = Convert.ToString(row.GetCell(2));
}
2.写EXCEL
XSSFWorkbook wb = new XSSFWorkbook();
ISheet sheet = wb.CreateSheet();
for(int i = 0; i < xmlContet.Count(); i++)
{
IRow irow = sheet.CreateRow(i);
ICell icell = irow.CreateCell(0);
icell.SetCellValue(xmlContet[i]);
}
using (FileStream fs = File.OpenWrite(xmlFile + ".xlsx"))
{
wb.Write(fs);
wb.Close();
fs.Close();
}
发表评论 取消回复