Exemplo n.º 1
0
        private static void CellPadding(string value, ICell cell, Tk5FieldInfoEx fieldInfo)
        {
            Tk5ExtensionConfig exConfig = fieldInfo.Extension;

            if (exConfig != null && exConfig.Format != null)
            {
                string strformat = string.Format(ObjectUtil.SysCulture, "{{0:{0}}}", exConfig.Format);
                string result    = string.Format(ObjectUtil.SysCulture, strformat, value);
                cell.SetCellValue(result);
            }
            else
            {
                switch (fieldInfo.DataType)
                {
                case TkDataType.Long:
                case TkDataType.Int:
                case TkDataType.Short:
                case TkDataType.Byte:
                case TkDataType.Double:
                case TkDataType.Decimal:
                case TkDataType.Money:
                    double number = value.Value <double>();
                    cell.SetCellValue(number);
                    break;

                case TkDataType.String:
                case TkDataType.Text:
                case TkDataType.Guid:
                case TkDataType.Xml:
                    cell.SetCellValue(value);
                    break;

                case TkDataType.DateTime:
                case TkDataType.Date:
                    DateTime dt = value.Value <DateTime>();
                    cell.SetCellValue(dt);
                    break;
                }
            }
        }
Exemplo n.º 2
0
        // 有DataTable生成Excel
        private static void DataTableExport(ExportExcelPageMaker configData,
                                            Dictionary <string, ICellStyle> contentStyles, ISheet sheet, DataTable dataTable)
        {
            int rowIndex = 1;

            foreach (DataRow row in dataTable.Rows)
            {
                IRow dataRow     = sheet.CreateRow(rowIndex);
                int  columnIndex = 0;
                foreach (Tk5FieldInfoEx fieldInfo in configData.fMetaData.Table.TableList)
                {
                    ICell cell = dataRow.CreateCell(columnIndex);

                    if (fieldInfo != null)
                    {
                        string             strValue = string.Empty;
                        Tk5ExtensionConfig ex       = fieldInfo.Extension;
                        SimpleFieldControl sfctrl   = fieldInfo.InternalControl;
                        if (fieldInfo.Decoder == null || fieldInfo.Decoder.Type == DecoderType.None)
                        {
                            strValue = (row[fieldInfo.NickName]).ToString();

                            if (!string.IsNullOrEmpty(strValue))
                            {
                                if (sfctrl != null && sfctrl.SrcControl == ControlType.CheckBox)
                                {
                                    if ((ex != null && strValue == ex.CheckValue) ||
                                        (ex == null && strValue == "1"))
                                    {
                                        cell.SetCellValue("√");
                                    }
                                }
                                else
                                {
                                    CellPadding(strValue, cell, fieldInfo);
                                }
                            }
                        }
                        else
                        {
                            strValue = row[fieldInfo.NickName + "_Name"].ToString();

                            if (!string.IsNullOrEmpty(strValue))
                            {
                                if (sfctrl != null &&
                                    (sfctrl.SrcControl == ControlType.CheckBoxList ||
                                     sfctrl.SrcControl == ControlType.MultipleEasySearch))
                                {
                                    MultipleDecoderData data = MultipleDecoderData.ReadFromString(strValue);
                                    cell.SetCellValue(string.Join(", ", data));
                                }
                                else
                                {
                                    cell.SetCellValue(strValue);
                                }
                            }
                        }
                        cell.CellStyle = contentStyles[fieldInfo.NickName];
                    }
                    columnIndex++;
                }
                rowIndex++;
            }
        }