The Winnovative Excel Library for .NET can be linked into any type
of .NET 2.0, 3.5 or 4.0 project, either ASP.NET web sites or Windows Forms and WPF
applications, to enable your application to create new Excel documents from scratch
or to edit existing Excel documents. The Winnovative Excel Library for .Net offers
support both for the old Excel 97-2003 format (.xls) and for the
new Excel 2007 and Excel 2010 (.xlsx) format.
The library is a .NET managed assembly and does not depend on Microsoft Office
Excel. The library can also be used from ASP.NET applications running
in more restrictive environments like servers where the trust level for the ASP.NET
application was restricted to Medium Trust by the server administrator.
The integration is extremely easy and no additional installation is necessary
in order to get started. The library is delivered as a strong named assembly that
can be directly referenced by your project. The downloaded archive contains C# and
VB.NET samples for ASP.NET and Windows Forms and the complete API documentation.
For a quick overview of the main capabilities of the library, a
main features demo was made available online on our website.
The dynamic invoices demo shows
how to dynamically create Excel invoices containing images, data tables and charts.
The full C# and VB.NET source code of the online demo applications is available
in the downloaded archive under the WnvExcelLib\Samples\AspNet folder.
Excel Library Features
- Easy integration, no installation or setup is necessary
- Deployed as single strong named .NET assembly
- Can be used from any .NET application (ASP.NET, Windows Forms, WPF)
- Does not depend on Microsoft Office Excel
- Can run in Medium Trust environments (like shared hosting)
- Can run on 32-bit and 64-bit Windows servers
- Create new Excel documents or edit existing Excel documents
- Support for Excel 97-2003 (.xls), Excel 2007 and 2010 (.xlsx) formats
- Load a workbook from a stream or from a file
- Save a workbook to a stream or to a file
- Load data from CSV files and save data to CSV format
- Load data from a .NET DataTable or save data to a DataTable object
- Add chart shapes or chart worksheets to a workbook
- Add formulas and array formulas to a worksheet
- Add global styles to a workbook
- Advanced support for Excel 2007 and 2010 gradients and textures
- Add named ranges at worksheet or workbook level
- Add images to a worksheet
- Add hyperlinks and comments to a worksheet
- Support for data validation
- Support for workbook windows and structure protection
- Support for worksheet data protection
- Read and write password protection for .xls workbooks
- Support for worksheet page setup - headers, footers, size, margins, orientation
- Support for workbook properties - author, subject, comments
Code Sample
protected void lnkBtnCreateWorkbook_Click(object sender, EventArgs e)
{
// get the Excel workbook format
ExcelWorkbookFormat workbookFormat = radioXlsFormat.Checked ? ExcelWorkbookFormat.Xls_2003 :
ExcelWorkbookFormat.Xlsx_2007;
// create the workbook in the desired format with a single worksheet
ExcelWorkbook workbook = new ExcelWorkbook(workbookFormat);
// set the license key before saving the workbook
workbook.LicenseKey = "RW51ZXZ0ZXVldGt1ZXZ0a3R3a3x8fHw=";
// set workbook description properties
workbook.DocumentProperties.Subject = "Getting started sample";
workbook.DocumentProperties.Comments = "Getting started with Winnovative
Excel library for .NET";
#region CREATE CUSTOM WORKBOOK STYLES
#region Add a style used for the cells in the worksheet title area
ExcelCellStyle titleStyle = workbook.Styles.AddStyle("WorksheetTitleStyle");
// center the text in the title area
titleStyle.Alignment.HorizontalAlignment = ExcelCellHorizontalAlignmentType.Center;
titleStyle.Alignment.VerticalAlignment = ExcelCellVerticalAlignmentType.Center;
if (workbookFormat == ExcelWorkbookFormat.Xls_2003)
{
// set the solid fill for the title area range with a custom color
titleStyle.Fill.FillType = ExcelCellFillType.SolidFill;
titleStyle.Fill.SolidFillOptions.BackColor = Color.FromArgb(255, 255, 204);
}
else
{
// set the gradient fill for the title area range with a custom color
titleStyle.Fill.FillType = ExcelCellFillType.GradientFill;
titleStyle.Fill.GradientFillOptions.Color1 = Color.FromArgb(255, 255, 204);
titleStyle.Fill.GradientFillOptions.Color2 = Color.White;
}
// set the title area font
titleStyle.Font.Size = 14;
titleStyle.Font.Bold = true;
titleStyle.Font.UnderlineType = ExcelCellUnderlineType.Single;
#endregion
#endregion
// get the first worksheet in the workbook
ExcelWorksheet worksheet = workbook.Worksheets[0];
// set the default worksheet name
worksheet.Name = "Hello World";
#region WORKSHEET PAGE SETUP
// set worksheet paper size and orientation, margins, header and footer
worksheet.PageSetup.PaperSize = ExcelPagePaperSize.PaperA4;
worksheet.PageSetup.Orientation = ExcelPageOrientation.Portrait;
worksheet.PageSetup.LeftMargin = 1;
worksheet.PageSetup.RightMargin = 1;
worksheet.PageSetup.TopMargin = 1;
worksheet.PageSetup.BottomMargin = 1;
#endregion
#region WRITE THE WORKSHEET TOP TITLE
// merge the cells in the range to create the title area
worksheet["A2:G3"].Merge();
// gets the merged range containing the top left cell of the range
ExcelRange titleRange = worksheet["A2"].MergeArea;
// set the text of title area
worksheet["A2"].Text = "Say 'Hello World'
in Different Languages";
// set a row height of 18 points for each row in the range
titleRange.RowHeightInPoints = 18;
// set the worksheet top title style
titleRange.Style = titleStyle;
#endregion
// SAVE THE WORKBOOK
// Save the Excel document in the current HTTP response stream
string outFileName = workbookFormat == ExcelWorkbookFormat.Xls_2003 ? "GettingStarted.xls" :
"GettingStarted.xlsx";
System.Web.HttpResponse httpResponse = System.Web.HttpContext.Current.Response;
// Prepare the HTTP response stream for saving the Excel document
// Clear any data that might have been previously buffered in the
output stream
httpResponse.Clear();
// Set output stream content type for Excel 97-2003 (.xls) or Excel
2007 (.xlsx)
if (workbookFormat == ExcelWorkbookFormat.Xls_2003)
httpResponse.ContentType = "Application/x-msexcel";
else
httpResponse.ContentType = "Application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
// Add the HTTP header to announce the Excel document either as an
attachment or inline
httpResponse.AddHeader("Content-Disposition", String.Format("attachment; filename={0}",
outFileName));
// Save the workbook to the current HTTP response output stream
// and close the workbook after save to release all the allocated
resources
try
{
workbook.Save(httpResponse.OutputStream);
}
finally
{
// close the workbook and release the allocated resources
workbook.Close();
}
// End the response and finish the execution of this page
httpResponse.End();
}