/// <summary> /// Creazione riga Header /// </summary> /// <param name="worksheetExporter">Exporter (per stream)</param> /// <param name="Headers">Colonne Header aggiuntive (da definizione tabelle)</param> /// <param name="settings">Impostazioni esportazione - per future configurazioni</param> private static void ExportHeaderRows( IWorksheetExporter worksheetExporter, string[] Headers, dto.dtoEcoTableExportSettings settings, string TableName) { // Nome tabella if (!string.IsNullOrWhiteSpace(TableName)) { using (IRowExporter rowExporter = worksheetExporter.CreateRowExporter()) { rowExporter.SetHeightInPoints(settings.HeaderRowHeight); using (ICellExporter cellExporter = rowExporter.CreateCellExporter()) { cellExporter.SetFormat(settings.HeaderFormat); cellExporter.SetValue(TableName.Replace(" ", " ")); } } } using (IRowExporter rowExporter = worksheetExporter.CreateRowExporter()) { rowExporter.SetHeightInPoints(settings.HeaderRowHeight); foreach (string hval in Headers) { using (ICellExporter cellExporter = rowExporter.CreateCellExporter()) { cellExporter.SetFormat(settings.HeaderFormat); cellExporter.SetValue(hval.Replace(" ", " ")); } } for (int i = 0; i < settings.HeadStrings.Length; i++) { using (ICellExporter cellExporter = rowExporter.CreateCellExporter()) { cellExporter.SetFormat(settings.HeaderFormat); cellExporter.SetValue(settings.HeadStrings[i]); } } } }
/// <summary> /// Crea via stream un documento Excel (csv non previsto per via di fogli multipli) con tutte le tabelle economiche di una valutazione /// </summary> /// <param name="Eval">Dati valutazione (definizioni, tabelle, ammissioni, importi)</param> /// <param name="documentStream">Stream output</param> /// <param name="DocFormat">Formato - Solo XLSX</param> /// <param name="settings">Impostazioni di esportazione (caratteri, larghezze, colori) - Per personalizzazioni future.</param> public static void EcoEvalTableExportStream( Eco.Domain.EconomicEvaluation Eval, Stream documentStream, SpreadDocumentFormat DocFormat = SpreadDocumentFormat.Xlsx, dto.dtoEcoTableExportSettings settings = null) { if (settings == null) { settings = new dto.dtoEcoTableExportSettings(); } int exportedCellsCount = 0; SpreadDocumentFormat selectedDocumentFormat; int totalCellsCount; DateTime exportStarted; bool canExport; if (Eval == null || Eval.Tables == null || !Eval.Tables.Any()) { return; } using (IWorkbookExporter workbookExporter = SpreadExporter.CreateWorkbookExporter(DocFormat, documentStream)) { int SheetNumber = 0; foreach (Eco.Domain.EconomicTable table in Eval.Tables) { if (table != null && table.FieldDefinition != null) { SheetNumber++; int headCols = table.HeaderValues.Count(); int totalCols = headCols + 7; string sheetName = string.Format("{0}-{1}", SheetNumber, table.FieldDefinition.Name); if (sheetName.Length > 25) { sheetName = string.Format("{0}...", sheetName.Substring(0, 20)); } sheetName = CleanFileName(sheetName); using (IWorksheetExporter worksheetExporter = workbookExporter.CreateWorksheetExporter(sheetName)) { for (int i = 0; i < totalCols; i++) { using (IColumnExporter columnExporter = worksheetExporter.CreateColumnExporter()) { if (i >= headCols) { columnExporter.SetWidthInCharacters(settings.ColumnWidths[i - headCols]); } else { columnExporter.SetWidthInCharacters(settings.ColumnAddWidth); } } } ExportHeaderRows(worksheetExporter, table.HeaderValues, settings, table.FieldDefinition.Name); foreach (AdvEconomic.Domain.EconomicItem itm in table.Items) { using (IRowExporter rowExporter = worksheetExporter.CreateRowExporter()) { rowExporter.SetHeightInPoints(settings.RowHeight); int columnIndex = 0; int iv = 0; foreach (string value in itm.InfoValues) { iv++; if (iv <= headCols) { using (ICellExporter cellExporter = rowExporter.CreateCellExporter()) { cellExporter.SetFormat(dto.dtoEcoTableExportSettings.InvalidCellFormat(settings.NormalFormat, itm.IsAdmit)); cellExporter.SetValue(value.Replace(" ", " ")); } } } if (iv < headCols) { using (ICellExporter cellExporter = rowExporter.CreateCellExporter()) { cellExporter.SetFormat(dto.dtoEcoTableExportSettings.InvalidCellFormat(settings.NormalFormat, itm.IsAdmit)); cellExporter.SetValue(""); } } //Quantità using (ICellExporter cellExporter = rowExporter.CreateCellExporter()) { cellExporter.SetFormat(dto.dtoEcoTableExportSettings.InvalidCellFormat(settings.DoubleFormat, itm.IsAdmit)); cellExporter.SetValue(itm.RequestQuantity); } //Prezzo unitario using (ICellExporter cellExporter = rowExporter.CreateCellExporter()) { cellExporter.SetFormat(dto.dtoEcoTableExportSettings.InvalidCellFormat(settings.DoubleEcoFormat, itm.IsAdmit)); cellExporter.SetValue(itm.RequestUnitPrice); } //Totale richiesto using (ICellExporter cellExporter = rowExporter.CreateCellExporter()) { cellExporter.SetFormat(dto.dtoEcoTableExportSettings.InvalidCellFormat(settings.DoubleEcoFormat, itm.IsAdmit)); cellExporter.SetValue(itm.RequestTotal); } //Approvato using (ICellExporter cellExporter = rowExporter.CreateCellExporter()) { cellExporter.SetFormat(dto.dtoEcoTableExportSettings.InvalidCellFormat(settings.NormalFormat, itm.IsAdmit)); cellExporter.SetValue(itm.IsAdmit ? settings.BoolValue[1] : settings.BoolValue[0]); } //Quantità ammessa using (ICellExporter cellExporter = rowExporter.CreateCellExporter()) { cellExporter.SetFormat(dto.dtoEcoTableExportSettings.InvalidCellFormat(settings.DoubleFormat, itm.IsAdmit)); cellExporter.SetValue(itm.AdmitQuantity); } //Totale ammesso using (ICellExporter cellExporter = rowExporter.CreateCellExporter()) { cellExporter.SetFormat(dto.dtoEcoTableExportSettings.InvalidCellFormat(settings.DoubleEcoFormat, itm.IsAdmit)); cellExporter.SetValue(itm.AdmitTotal); } //Commenti using (ICellExporter cellExporter = rowExporter.CreateCellExporter()) { cellExporter.SetFormat(dto.dtoEcoTableExportSettings.InvalidCellFormat(settings.NormalFormat, itm.IsAdmit)); if (itm.Comment != null) { cellExporter.SetValue(itm.Comment.Replace(" ", " ").Replace("<br>", "\r\n")); } else { cellExporter.SetValue(""); } } } } } } } } }