Manipulating xlsx files in .NET can appear complicated and tedious however, doing so only requires a few lines of codes while using Xceed Workbooks for .NET. Let’s look at a quick example :
To Open an existing xlsx :
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.
}
As you can see, with just a few lines of codes you’ll be able to create/modify/load workbooks. We offer a trial version of the product should you want to try it for yourself. We’re available on both Nuget and directly on our website : https://xceed.com/en/our-products/product/workbooks-for-net (click on try it now).
Have questions or issues? Drop us an email at support@xceed.com.
Have fun!