Ejemplo n.º 1
0
        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));
            }

            var srcWb = WorkbookFactory.Create(path);
            var wb    = new ExcelWorkbook();

            for (int i = 0; i < srcWb.NumberOfSheets; i++)
            {
                var srcSheet = srcWb.GetSheetAt(i);
                wb.Sheets.Add(srcSheet.SheetName, ExcelSheet.Create(srcSheet, config));
            }

            return(wb);
        }
Ejemplo n.º 2
0
        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);
        }