Exemple #1
0
        internal static object GetPropertyFromCellValue(string stringValue, ExcelFormatType format = ExcelFormatType.Unknown)
        {
            if (format == ExcelFormatType.Text)
            {
                return(stringValue);
            }

            try
            {
                return(JToken.Parse(stringValue));
            }
            catch (JsonReaderException)
            {
                return(stringValue);
            }
        }
        private void FormatNumberCell(ExcelWorksheet worksheet, DataTable dataTable, int currentRowWorksheet, int currentRowDataTable, int currentColumnWorksheet,
                                      int currentColumnDataTable, ExcelFormatType excelFormatType)
        {
            var columnCount = dataTable.Columns.Count;

            var worksheetCell = worksheet.Cells[currentRowWorksheet, currentColumnWorksheet];
            var dataItem      = currentColumnDataTable < columnCount ? dataTable.Rows[currentRowDataTable][currentColumnDataTable] : null;
            var excelCell     = (ExcelCell)dataItem;

            if (excelCell != null)
            {
                switch (excelFormatType)
                {
                case ExcelFormatType.IntNullable:
                    worksheetCell.Value = Parser.ParseNullableInt(excelCell.CellValue?.ToString());
                    FormatNumber(worksheetCell, ExportConstants.IntExcelFormatTemplate);
                    break;

                case ExcelFormatType.Date:
                    worksheetCell.Value = DateTime.Parse(excelCell.CellValue.ToString());
                    FormatNumber(worksheetCell, ExportConstants.DateExcelFormatTemplate);
                    break;

                case ExcelFormatType.DateNullable:
                    worksheetCell.Value = Parser.ParseNullableDateTime(excelCell.CellValue?.ToString());
                    FormatNumber(worksheetCell, ExportConstants.DateExcelFormatTemplate);
                    break;

                case ExcelFormatType.AccountingNullable:
                    var currencySymbol = (ExcelCell)dataTable.Rows[currentRowDataTable][ExportConstants.CurrencySymbolColumnName];

                    worksheetCell.Value = Parser.ParseNullableFloat(excelCell.CellValue?.ToString());
                    FormatNumber(worksheetCell, ExportConstants.CreateAccountingExcelFormatTemplate(currencySymbol.CellValue?.ToString()));
                    break;

                default: throw new Exception("Inccorect excel format type");
                }
            }
        }