Example #1
0
        // 由微信类生成Excel
        private void ObjectExport(Dictionary <string, ICellStyle> ContentStyles,
                                  ISheet sheet, ObjectListModel objectLM)
        {
            int rowIndex = 1;

            foreach (ObjectContainer container in objectLM.List)
            {
                IRow   dataRow     = sheet.CreateRow(rowIndex);
                int    columnIndex = 0;
                object receiver    = container.MainObject;
                string strValue    = string.Empty;
                foreach (Tk5FieldInfoEx fieldInfo in fMetaData.Table.TableList)
                {
                    ICell cell = dataRow.CreateCell(columnIndex);

                    if (fieldInfo != null)
                    {
                        if (fieldInfo.Decoder == null || fieldInfo.Decoder.Type == DecoderType.None)
                        {
                            strValue = receiver.MemberValue(fieldInfo.NickName).ConvertToString();
                            ExcelUtil.CellPadding(strValue, cell, fieldInfo);
                        }
                        else
                        {
                            strValue = container.Decoder.GetNameString(fieldInfo.NickName);
                        }

                        cell.CellStyle = ContentStyles[fieldInfo.NickName];
                    }
                    columnIndex++;
                }
                rowIndex++;
            }
        }
Example #2
0
        // 由DataTable生成Excel
        private void DataTableExport(Dictionary <string, ICellStyle> ContentStyles,
                                     ISheet sheet, DataTable dt)
        {
            int rowIndex = 1;

            foreach (DataRow row in dt.Rows)
            {
                IRow dataRow     = sheet.CreateRow(rowIndex);
                int  columnIndex = 0;
                foreach (Tk5FieldInfoEx fieldInfo in 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
                                {
                                    ExcelUtil.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++;
            }
        }