Ejemplo n.º 1
0
    public static XlsInput Load(string xlsFilePath)
    {
        if (!File.Exists(xlsFilePath))
        {
            throw new FileNotFoundException();
        }

        List <XlsWorksheetInfo> worksheets = new();

        XlsUtil.WithWorkbook(xlsFilePath, workbook => {
            var sheets    = workbook.ReadWorksheetNames();
            var numSheets = sheets.Count;

            if (numSheets == 0)
            {
                throw new Exception("This workbook does not contain any sheets.");
            }

            for (var i = 0; i < numSheets; i++)
            {
                worksheets.Add(XlsWorksheetInfo.Load(workbook, i));
            }
        });

        return(new() {
            FilePath = xlsFilePath,
            Worksheets = worksheets
        });
    }
Ejemplo n.º 2
0
        private void Import()
        {
            XlsUtil.WithWorkbook(_filePath, workbook => {
                var sheet = workbook.GetSheetAt(GetSheetIndex(workbook));
                var rows  = XlsUtil.ReadSheet(sheet, _firstRowIndex, _lastRowIndex, _firstColumnIndex, _lastColumnIndex);

                SqlUtil.Import(
                    srcColNames: XlsUtil.ReadColumnNames(rows, _headerRow),
                    dataRows: rows.Skip(_headerRow ? 1 : 0),
                    importTable: _stmt.ImportTable,
                    temporaryTable: _temporaryTable,
                    truncateExistingTable: _truncateExistingTable,
                    ifConversionFails: _ifConversionFails,
                    notebook: _notebook,
                    runner: _runner,
                    env: _env);
            });
        }
Ejemplo n.º 3
0
    private void Import()
    {
        XlsUtil.WithWorkbook(_filePath, workbook => {
            workbook.SeekToWorksheet(GetSheetIndex(workbook));
            var rows = workbook.ReadSheet(_firstRowIndex, _lastRowIndex, _firstColumnIndex, _lastColumnIndex);

            SqlUtil.Import(
                srcColNames: XlsUtil.ReadColumnNames(rows, _headerRow),
                dataRows: rows.Skip(_headerRow ? 1 : 0),
                importTable: _stmt.ImportTable,
                temporaryTable: _temporaryTable,
                truncateExistingTable: _truncateExistingTable,
                stopAtFirstBlankRow: _stopAtFirstBlankRow,
                ifConversionFails: _ifConversionFails,
                blankValuesMethod: _blankValuesMethod,
                notebook: _notebook,
                runner: _runner,
                env: _env);
        });
    }