Ejemplo n.º 1
0
        private void ImportFile(string FileName)
        {
            try
            {
                XlsFile xls = new XlsFile();
                xls.VirtualMode = true; //Remember to turn virtual mode on, or the event won't be called.

                //By default, FlexCel returns the formula text for the formulas, besides its calculated value.
                //If you are not interested in formula texts, you can gain a little performance by ignoring it.
                //This also works in non virtual mode.
                xls.IgnoreFormulaText = cbIgnoreFormulaText.Checked;

                CellData = new SparseCellArray();

                //Attach the CellReader handler.
                CellReader cr = new CellReader(cbFirst50Rows.Checked, CellData, cbFormatValues.Checked);
                xls.VirtualCellStartReading += new VirtualCellStartReadingEventHandler(cr.OnStartReading);
                xls.VirtualCellRead         += new VirtualCellReadEventHandler(cr.OnCellRead);

                DateTime StartOpen = DateTime.Now;

                //Open the file. As we have a CellReader attached, the cells won't be loaded into memory, they will be passed to the CellReader
                xls.Open(FileName);
                DateTime StartSheetSelect = cr.StartSheetSelect;
                DateTime EndSheetSelect   = cr.EndSheetSelect;

                DateTime EndOpen = DateTime.Now;
                statusBar.Text = "Time to open file: " + (StartSheetSelect - StartOpen).ToString() + "     Time to load file and fill grid: " + (EndOpen - EndSheetSelect).ToString();

                //Set up grid.
                GridCaption.Text = FileName;
                if (CellData != null)
                {
                    DisplayGrid.ColumnCount = CellData.ColCount;
                    DisplayGrid.RowCount    = CellData.RowCount;
                }
                else
                {
                    DisplayGrid.ColumnCount = 0;
                    DisplayGrid.RowCount    = 0;
                }

                for (int i = 0; i < DisplayGrid.ColumnCount; i++)
                {
                    DisplayGrid.Columns[i].Name = TCellAddress.EncodeColumn(i + 1);
                }
            }
            catch
            {
                GridCaption.Text = "Error Loading File";
                CellData         = null;
                throw;
            }
        }
Ejemplo n.º 2
0
 public CellReader(bool aOnly50Rows, SparseCellArray aCellData, bool aFormatValues)
 {
     Only50Rows   = aOnly50Rows;
     CellData     = aCellData;
     FormatValues = aFormatValues;
 }