Esempio n. 1
0
        public void Export(int sheetIndex, int rowIndexStart, int columnIndexStart, System.Data.DataTable dtExport, bool isAddTitle)
        {
            Worksheet sheet = GetSheet(sheetIndex);

            System.Data.DataTable dtExportPage = dtExport.Clone();
            string[,] arrExportPage = null;
            Range range = null;

            int dataColumnCount = dtExport.Columns.Count;

            if (isAddTitle)
            {
                arrExportPage = new string[1, dataColumnCount];
                for (int indexColumn = 0; indexColumn < dataColumnCount; indexColumn++)
                {
                    arrExportPage[0, indexColumn] = dtExport.Columns[indexColumn].ColumnName;
                }

                range = GetRange(sheet, rowIndexStart, columnIndexStart, rowIndexStart, columnIndexStart + dataColumnCount - 1);
                range.Value2 = arrExportPage;
                range.Value2 = range.Value2;

                rowIndexStart++;
            }

            int pageSize = 10000;
            int currentDataRowIndex = 0;
            while (currentDataRowIndex < dtExport.Rows.Count)
            {
                dtExportPage.Rows.Add(dtExport.Rows[currentDataRowIndex].ItemArray);

                if ((currentDataRowIndex + 1) % pageSize == 0)
                {
                    arrExportPage = Tools.DataTableToArray(dtExportPage, false);
                    range = GetRange(sheet, rowIndexStart, columnIndexStart, rowIndexStart + dtExportPage.Rows.Count - 1, columnIndexStart + dataColumnCount - 1);
                    range.Value2 = arrExportPage;
                    range.Value2 = range.Value2;

                    rowIndexStart += dtExportPage.Rows.Count;

                    dtExportPage.Rows.Clear();
                }

                currentDataRowIndex++;
            }

            //ʣ����޷�ȡ������
            arrExportPage = Tools.DataTableToArray(dtExportPage, false);
            range = GetRange(sheet, rowIndexStart, columnIndexStart, rowIndexStart + dtExportPage.Rows.Count - 1, columnIndexStart + dataColumnCount - 1);
            range.Value2 = arrExportPage;
            range.Value2 = range.Value2;

            dtExportPage.Rows.Clear();
        }