Exemplo n.º 1
0
        public void Write(Stream stream, string templatePath, DataSet ds, ExcelExtendType extendType = ExcelExtendType.XLSX)
        {
            TemplateConfig config = new TemplateConfig();

            config.Load(templatePath);
            TTemplate template = config.GetTemplate();

            Write(stream, template, ds);
        }
Exemplo n.º 2
0
        public bool WriteFile(string outputFilePath, DataSet ds, TTemplate template)
        {
            POIStream stream = new POIStream();

            stream.AllowClose = false;
            ExcelExtendType extendType = outputFilePath.IndexOf(".xlsx") > 0 ? ExcelExtendType.XLSX : ExcelExtendType.XLS;

            if (template == null)
            {
                Write(stream, ds, extendType);
            }
            else
            {
                Write(stream, template, ds, extendType);
            }
            bool result = WriteFile(outputFilePath, stream);

            return(result);
        }
Exemplo n.º 3
0
        public void Write(Stream stream, TTemplate template, DataSet ds, ExcelExtendType extendType = ExcelExtendType.XLSX)
        {
            if (extendType == ExcelExtendType.XLS)
            {
                workbook = new HSSFWorkbook();
            }
            else
            {
                workbook = new XSSFWorkbook();
            }
            foreach (TSheet tSheet in template.Sheets)
            {
                ISheet sheet     = workbook.CreateSheet(tSheet.Title);
                string tableName = string.IsNullOrEmpty(tSheet.Name) ? tSheet.Title : tSheet.Name;
                fillSheet(sheet, tSheet, ds.Tables[tableName]);
            }

            workbook.Write(stream);
        }