Ejemplo n.º 1
0
        protected virtual Worksheet CreateSheet(XlsDocument xlsDoc, int sheetIndex, IList <ColumnSetting <T> > columnMap, string title, out int startDataRowIndex)
        {
            Worksheet worksheet      = xlsDoc.Workbook.Worksheets.Count > 0 ? xlsDoc.Workbook.Worksheets[0] : xlsDoc.Workbook.Worksheets.Add("Sheet" + sheetIndex.ToString());
            int       headerRowIndex = 1;

            //if (string.IsNullOrWhiteSpace(templateExcelPath))
            //{
            if (!string.IsNullOrWhiteSpace(title))
            {
                ExcelFileExporterHelper.MergeRegion(worksheet, ExcelFileExporterHelper.GetSheetTitleXF(xlsDoc), title.Trim(), headerRowIndex, 1, headerRowIndex, columnMap.Count);
                headerRowIndex = headerRowIndex + 1;
            }
            var xf            = ExcelFileExporterHelper.GetDataCellXF(xlsDoc);
            int excelColIndex = 0;

            foreach (var col in columnMap)
            {
                excelColIndex++;
                worksheet.Cells.Add(headerRowIndex, excelColIndex, col.ColumnName, xf);
            }

            decimal[] rstContainer = new decimal[columnMap.Count];
            headerRowIndex    = headerRowIndex + 1;
            startDataRowIndex = headerRowIndex;
            return(worksheet);
        }
Ejemplo n.º 2
0
        public virtual string Export(List <T> data, IList <ColumnSetting <T> > columnMap, string title = null)
        {
            XlsDocument xlsDoc = new XlsDocument();

            if (data != null)
            {
                BuildSheet(xlsDoc, 1, data, columnMap, title);
            }
            string fileName = ExcelFileExporterHelper.GetFileName(title);

            xlsDoc.FileName = fileName;
            xlsDoc.Save(ExcelFileExporterHelper.ExportFileFolder, true);
            return(fileName);
        }
Ejemplo n.º 3
0
        protected virtual void BuildSheetData(XlsDocument xlsDoc, Worksheet worksheet, int startRowIndex, List <T> data, IList <ColumnSetting <T> > columnMap)
        {
            var xf = ExcelFileExporterHelper.GetDataCellXF(xlsDoc);
            int j  = 0;

            for (j = 0; j < data.Count; j++)
            {
                for (int c = 1; c <= columnMap.Count; c++)
                {
                    var    columnSetting = columnMap[c - 1];
                    object d             = columnSetting.GetPropertyValue(data[j]);
                    worksheet.Cells.Add(j + startRowIndex, c, d, xf);
                }
            }
        }