예제 #1
0
        private void InsertDataTableRows(Worksheet worksheet, ExcelDataTable excelDataTable)
        {
            int rowCount      = excelDataTable.RowCount;
            int colCount      = excelDataTable.ColumnCount;
            int startRowIndex = excelDataTable.StartRowIndex;
            int startColIndex = excelDataTable.StartColumnIndex;

            int colIndex;

            for (int rowIndex = 1; rowIndex <= rowCount; rowIndex++)
            {
                for (colIndex = 0; colIndex < colCount; colIndex++)
                {
                    string result = excelDataTable.GetCellValueAt(rowIndex - 1, colIndex);
                    double number;
                    if (Double.TryParse(result, out number))
                    {
                        Range numberRange = worksheet.Cells[startRowIndex + rowIndex, startColIndex + colIndex];
                        numberRange.NumberFormat = "0.0000";
                    }
                    worksheet.Cells[startRowIndex + rowIndex, startColIndex + colIndex] = result != "" ?
                                                                                          result : "=NA()";
                }
            }
        }