public static void insertExcelData(string folderPath, string fileName, string[] args) { try { HSSFWorkbook wb = new HSSFWorkbook(); HSSFCreationHelper createHelper = (HSSFCreationHelper)wb.GetCreationHelper(); using (FileStream file = new FileStream(folderPath + "\\" + fileName, FileMode.Open, FileAccess.Read)) { wb = new HSSFWorkbook(file); } ISheet sheet = wb.GetSheet("219Option"); IRow row = sheet.CreateRow(sheet.LastRowNum + 1); row.CreateCell(0).SetCellValue(createHelper.CreateRichTextString(args[1])); row.CreateCell(1).SetCellValue(createHelper.CreateRichTextString(args[2])); row.CreateCell(2).SetCellValue(createHelper.CreateRichTextString(args[3])); using (FileStream file = new FileStream(folderPath + "\\" + fileName, FileMode.Create, FileAccess.Write)) { wb.Write(file); file.Close(); } } catch (Exception ex) { Console.WriteLine("Occur error insertExcelData function : " + ex.ToString()); } }
public static void createExcelFile(string folderPath, string fileName) { try { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = (HSSFSheet)wb.CreateSheet("219Option"); HSSFRow row = (HSSFRow)sheet.CreateRow(0); HSSFCreationHelper createHelper = (HSSFCreationHelper)wb.GetCreationHelper(); row.CreateCell(0).SetCellValue(createHelper.CreateRichTextString("Option Name")); row.CreateCell(1).SetCellValue(createHelper.CreateRichTextString("Input Value")); row.CreateCell(2).SetCellValue(createHelper.CreateRichTextString("Output Value")); using (FileStream file = new FileStream(folderPath + "\\" + fileName, FileMode.Create, FileAccess.Write)) { wb.Write(file); file.Close(); } } catch (Exception ex) { Console.WriteLine("Occur error createExcelFile function : " + ex.ToString()); } }