Microsoft® Creazione di file basati su modelli Excel via .NET
Genera report su file Excel sulla base di un modello predefinito all'interno delle applicazioni basate su .NET
.NET Libreria Excel supporta la generazione di file Excel basati su modelli per la generazione di report in blocco. I modelli sono formati predefiniti, utilizzati per creare report con lo stesso modello. Il codice .NET crea il nuovo file Excel come il documento modello riempito con i dati. I formati di file supportati includono XLS, XLSX, XLSB, XLSM, ODS.
Crea report basati su modelli Excel predefiniti
Automatizzare il processo di creazione degli stessi file di pattern è semplice utilizzando .NET Assembly API. Esistono diversi modi per importare dati e generare file Excel. API fornisce a Classe WorkbookDesigner per rappresentare un foglio di lavoro del designer. Crea il suo oggetto e usalo per aprire il file modello. Imposta l’origine dati, che può essere DataTable, Array, file Json ecc. Elaborala per importare i dati e salva il file con i dati nel formato richiesto. I programmatori possono assemblare i dati in report in altri formati di file utilizzando i collegamenti elencati di seguito.
C# Codice per generare report Excel
// instantiate a new Workbook designer | |
var dgr = new WorkbookDesigner(); | |
// get the first worksheet of the workbook | |
var sheet = dgr.Workbook.Worksheets[0]; | |
// set the marker to a cell A1 | |
sheet.Cells["A1"].PutValue("&=$VariableArray"); | |
// set the data source for the marker | |
dgr.SetDataSource("VariableArray", new string[] { "first", "second", "third", "fourth", "fifth" }); | |
// To Set the datatable as the data source. Firstly populate datatable from any data source | |
// dgr.SetDataSource(dt); | |
// process the marker | |
dgr.Process(true); | |
// save the result in XLSX format | |
dgr.Workbook.Save("output.xlsx"); |