Esempio n. 1
0
        /// <summary>
        /// Sets the cell data.
        /// </summary>
        /// <param name="worksheet">The sheet</param>
        /// <param name="area">The area</param>
        /// <param name="rowIndex">Index of the row</param>
        /// <param name="columnIndex">Index of the column</param>
        /// <param name="value">The value</param>
        /// <param name="opt">The opt</param>
        static void SetCellData(Worksheet worksheet, SheetArea area, int rowIndex, int columnIndex, string value, ImportExportOptions opt)
        {
            object           obj2       = value;
            GeneralFormatter gformatter = null;

            if (!opt.UnFormatted)
            {
                gformatter = new GeneralFormatter().GetPreferredDisplayFormatter(value, out obj2) as GeneralFormatter;
            }
            if (obj2 == null)
            {
                worksheet.SetValue(rowIndex, columnIndex, area, obj2);
            }
            else if (!object.Equals(value, ""))
            {
                if (!opt.Formula || !value.StartsWith("="))
                {
                    StyleInfo info = worksheet.GetActualStyleInfo(rowIndex, columnIndex, area);
                    if (info != null)
                    {
                        if (!opt.UnFormatted)
                        {
                            if (info.Formatter == null)
                            {
                                SetFormatter(worksheet, rowIndex, columnIndex, area, gformatter);
                            }
                            else if (info.Formatter.FormatString == "@")
                            {
                                obj2 = value.ToString();
                            }
                        }
                        else if (info.Formatter != null)
                        {
                            if (area == SheetArea.Cells)
                            {
                                worksheet.Cells[rowIndex, columnIndex].ResetFormatter();
                            }
                            if (area == (SheetArea.CornerHeader | SheetArea.RowHeader))
                            {
                                worksheet.RowHeader.Cells[rowIndex, columnIndex].ResetFormatter();
                            }
                            if (area == SheetArea.ColumnHeader)
                            {
                                worksheet.ColumnHeader.Cells[rowIndex, columnIndex].ResetFormatter();
                            }
                        }
                    }
                    worksheet.SetValue(rowIndex, columnIndex, area, obj2);
                }
                else
                {
                    try
                    {
                        worksheet.SetFormula(rowIndex, columnIndex, area, value.Substring(1));
                    }
                    catch
                    {
                        worksheet.SetText(rowIndex, columnIndex, area, value);
                    }
                }
            }
            else
            {
                worksheet.SetValue(rowIndex, columnIndex, area, null);
            }
        }