public static ExcelWorkbook Create(string path, ExcelSheetReadConfig config) { if (Path.GetExtension(path) == ".csv") { return(CreateFromCsv(path, config)); } if (Path.GetExtension(path) == ".tsv") { return(CreateFromTsv(path, config)); } string tmpFile = Path.GetTempFileName(); File.Copy(path, tmpFile, true); var srcWb = new XSSFWorkbook(tmpFile); var wb = new ExcelWorkbook(); wb.rawFilePath = path; wb.rawWorkbook = srcWb; for (int i = 0; i < srcWb.NumberOfSheets; i++) { var srcSheet = srcWb.GetSheetAt(i); wb.Sheets.Add(srcSheet.SheetName, ExcelSheet.Create(srcSheet, config)); wb.SheetNames.Add(srcSheet.SheetName); } return(wb); }
private static ExcelSheet CreateSheet(IEnumerable <ExcelRow> rows, ExcelSheetReadConfig config) { var sheet = CreateSheet(rows); if (config.TrimFirstBlankRows) { sheet.TrimFirstBlankRows(); } if (config.TrimFirstBlankColumns) { sheet.TrimFirstBlankColumns(); } if (config.TrimLastBlankRows) { sheet.TrimLastBlankRows(); } if (config.TrimLastBlankColumns) { sheet.TrimLastBlankColumns(); } return(sheet); }
public static ExcelWorkbook Create(string path, ExcelSheetReadConfig config, int sheetIndex = -1) { if (Path.GetExtension(path) == ".csv") { return(CreateFromCsv(path, config)); } if (Path.GetExtension(path) == ".tsv") { return(CreateFromTsv(path, config)); } var srcWb = WorkbookFactory.Create(path); var wb = new ExcelWorkbook(); if (sheetIndex > -1 && sheetIndex < srcWb.NumberOfSheets) { var srcSheet = srcWb.GetSheetAt(sheetIndex); wb.Sheets.Add(srcSheet.SheetName, ExcelSheet.Create(srcSheet, config)); } else { for (int i = 0; i < srcWb.NumberOfSheets; i++) { var srcSheet = srcWb.GetSheetAt(i); wb.Sheets.Add(srcSheet.SheetName, ExcelSheet.Create(srcSheet, config)); } } return(wb); }
public ExcelSheet(IEnumerable <ExcelRow> rows, ExcelSheetReadConfig config) { Rows = new SortedDictionary <int, ExcelRow>(); foreach (var row in rows) { Rows.Add(row.Index, row); } if (config.TrimFirstBlankRows) { TrimFirstBlankRows(); } if (config.TrimFirstBlankColumns) { TrimFirstBlankColumns(); } if (config.TrimLastBlankRows) { TrimLastBlankRows(); } if (config.TrimLastBlankColumns) { TrimLastBlankColumns(); } }
private static ExcelWorkbook CreateFromCsv(string path, ExcelSheetReadConfig config) { var wb = new ExcelWorkbook(); wb.Sheets.Add(Path.GetFileName(path), ExcelSheet.CreateFromCsv(path, config)); return(wb); }
private static ExcelWorkbook CreateFromTsv(string path, ExcelSheetReadConfig config) { var wb = new ExcelWorkbook(); wb.Sheets.Add("tsv", ExcelSheet.CreateFromTsv(path, config)); return(wb); }
public static ExcelSheet CreateFromTsv(string path, ExcelSheetReadConfig config) { var rows = TsvReader.Read(path); var sheet = CreateSheet(rows, config); sheet.Name = "tsv"; return(sheet); }
public static ExcelSheet Create(ISheet srcSheet, ExcelSheetReadConfig config) { var rows = ExcelReader.Read(srcSheet); var sheet = CreateSheet(rows, config); sheet.Name = srcSheet.SheetName; sheet.Index = srcSheet.Workbook.GetSheetIndex(sheet.Name); return(sheet); }
public static ExcelWorkbook Create(string path, ExcelSheetReadConfig config, bool enableEdit = false) { if (Path.GetExtension(path) == ".csv") { return(CreateFromCsv(path, config)); } if (Path.GetExtension(path) == ".tsv") { return(CreateFromTsv(path, config)); } var wb = new ExcelWorkbook(); FileAccess access = enableEdit == true ? FileAccess.ReadWrite : FileAccess.Read; if (Path.GetExtension(path) == ".xlsm" || Path.GetExtension(path) == ".xlsx" || Path.GetExtension(path) == ".tmp") { FileStream stream = new FileStream(path, FileMode.OpenOrCreate, access, FileShare.ReadWrite); wb.srcWb = new XSSFWorkbook(stream); } else { wb.srcWb = WorkbookFactory.Create(path); } //wb.srcWb.Close(); wb.FilePath = path; for (int i = 0; i < wb.srcWb.NumberOfSheets; i++) { var srcSheet = wb.srcWb.GetSheetAt(i); wb.Sheets.Add(srcSheet.SheetName, ExcelSheet.Create(srcSheet, config)); } return(wb); }
public SVExcelSheet(string path, ExcelSheetReadConfig config) : base(ExcelReader.Read(path), config) { }
public XLSExcelSheet(ISheet originalSheet, ExcelSheetReadConfig config) : base(ExcelReader.Read(originalSheet), config) { rawSheet = originalSheet; }
public static ExcelSheet CreateFromCsv(string path, ExcelSheetReadConfig config) { var rows = CsvReader.Read(path); return(CreateSheet(rows, config)); }
public static ExcelSheet Create(ISheet srcSheet, ExcelSheetReadConfig config) { var rows = ExcelReader.Read(srcSheet); return(CreateSheet(rows, config)); }