La manipulation des fichiers xlsx dans .NET peut sembler compliquée et fastidieuse, mais elle ne nécessite que quelques lignes de code en utilisant Xceed Workbooks for .NET. Examinons un exemple rapide :
Pour ouvrir un fichier xlsx existant :
using( var doc = Workbook.Load( "test.xlsx") ) // Loads an existing Workbook named “test.xlsx”.{var worksheet = doc.Worksheets[ 1 ]; // Gets the second worksheet.worksheet.Cells[ “A2” ].Value = 12; // Sets a value in “A2”.var stream = new MemoryStream();doc.SaveAs( stream); // Saves the result in a stream.}
var stream = new MemoryStream();using( var doc = Workbook.Create( stream ) ) // Creates a workbook in a stream.{var worksheet = doc.Worksheets[ 1 ]; // Gets the second worksheet.worksheet.Cells[ “A2” ].Value = 12; // Sets a value in “A2”.worksheet.Columns[ 1 ].Cells[ 0 ].Formula = “=SUM(A1:A2)”; //Sets a formula in “B1”.doc.CalculateFormulas(); // Calculate the Value of “B1”, which contains a formula and for all other Worksheets containing cells with formulas.doc.Save(); // Saves the Workbook in the stream.}
Comme vous pouvez le constater, quelques lignes de code suffisent pour créer/modifier/charger des classeurs. Nous offrons une version d'essai du produit si vous voulez l'essayer par vous-même. Nous sommes disponibles à la fois sur Nuget et directement sur notre site web : http://xceed.com/en/our-products/product/workbooks-for-net (cliquez sur essayer maintenant).
Vous avez des questions ou des problèmes ? Envoyez-nous un courriel à support@xceed.com.
Amusez-vous bien !