I’m still looking at Excel components. From the same series so far:
- About Excel exporting in CarlosAG way
- About excel exporting using Winnovative Excel Library for .net
- About avoiding Excel exporting with Aspose Cells for .Net
This time I’ll try Nikasoft NativeExcel and follow the same procedure as in previous posts of the series.
What does it do ?
Works without Excel, creates Excel 97-2003 documents, which may contain formulas, images, formatting etc. See the feature list yourself. It seems to support everything I need.
What do I need ?
Support for data types, unicode, basic formatting, formulas, cell merge, column width – the same things as in my previous excel-component test.
What did I get ?
As already becoming a norm - functionally I got everything I wanted. Again, as I used demo version then it overwrote the top-left cell with warning “This worksheet was created by demo version of NativeExcel library”. I didn’t like that it overwrote my own text in there without warning which is more invasive than Winnovative’s extra sheet. In production I hope they’ll somehow lose it, I hope.
The file was a Excel 97-2003 xls file, And even though it provided tools to export Excel 5 and 97 version as well as CSV and a few more, it does NOT support xlsx. Not a big thing but a sign.
How did I do it ?
using System;
using System.Globalization;
using System.Threading;
using NativeExcel;
public class NativeExcelTest
{
private const int DummyRows = 15;
public static void Build()
{
//prepare sheet
IWorkbook book = NativeExcel.Factory.CreateWorkbook();
IWorksheet sheet = book.Worksheets.Add();
sheet.Name = "Sample";
//create data
int currentRow = 1;
//we can use excel style range instead of coordinates.
sheet.Cells["A1:D1"].Merge();
sheet.Cells["A1"].Value = "demonstrate merge";
BuildHeaderRow(sheet, ++currentRow);
for(int i = 1; i <= DummyRows; i++)
{
BuildDataRow(sheet, i, ++currentRow);
}
BuildSummaryRow(sheet, ++currentRow);
//corrigate column widths:
sheet.Cells.Autofit();
//output result
book.SaveAs("Native_result.xls");
}
private static void BuildHeaderRow(IWorksheet sheet, int toRow)
{
sheet.Cells[toRow, 1].Value = "index";
sheet.Cells[toRow, 2].Value = "1/index";
sheet.Cells[toRow, 3].Value = "name";
sheet.Cells[toRow, 4].Value = "datetime";
sheet.Cells[toRow, 1, toRow, 4].Font.Bold = true;
}
private static void BuildDataRow(IWorksheet sheet, int dataIndex, int toRow)
{
//generate dummy data row using dataIndex for values:
sheet.Cells[toRow, 1].Value = dataIndex;
sheet.Cells[toRow, 2].Value = 1.0M / dataIndex;
sheet.Cells[toRow, 3].Value = "Ilus õõvaöö nr "
+ dataIndex.ToString(CultureInfo.InvariantCulture);
sheet.Cells[toRow, 4].Value = DateTime.Today.AddDays(dataIndex);
}
private static void BuildSummaryRow(IWorksheet sheet, int toRow)
{
sheet.Cells[toRow, 1].Formula = String.Format("=AVERAGE(A{0}:A{1})", toRow - DummyRows, toRow - 1);
sheet.Cells[toRow, 2].Formula = String.Format("=SUM(B{0}:B{1})", toRow - DummyRows, toRow - 1);
sheet.Cells[toRow, 4].Formula = String.Format("=D{0}+1", toRow - 1);
//it didn't get the formula type correctly.
sheet.Cells[toRow, 4].NumberFormat
= Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern;
}
}
Some subjective numbers:
-
~64 lines of code (including empty lines, usings, etc)
-
runs approx 200-240 ms on E8300 @2.83GHz, 4GB RAM.
What do I think ?
Having previously tried Winnovative component, the transition was smooth and without serious problems. All differences for my simple testcase were rather small and syntactic. Maybe I’m biased, but it felt a bit messier than Winnovative component. But as there is also price difference then better try it out yourself before choosing one or the other.
The good
- mostly managed code, .Net fw 2.0
- Requires windows as there’s reference to GDI32.dll
- relatively cheap
- $140 (registered user licence)
- it seems there it may be with source code but without the right to modify
- not sure if licencees are named developers or how the number of development machines matter.
- unlimited deploy
- $450 (site licence)
- source code + right to recompile
- All employees can develop
- unlimited deploy
- $140 (registered user licence)
- Probably single dll deployment (~0.5 MB)
- Seems to do everything I need
- decent API
- friendly and flexible cell referencing tools, similar to those of Winnovative.
- indexed (row 1, col 1) or “A1”-style
- no adding of empty cells/rows as for CarlosAG.
- friendly and flexible cell referencing tools, similar to those of Winnovative.
- Some documentation in web (mostly in the form of code samples
The bad:
- Not free
- see the prices mentioned above. Not much but more than nothing.
- No xlsx
- It probably is not so important to end-users, but I like the idea of the new format. Not to mentioned this is the format to be supported by Excel longer and better than the older one.
- No xmldoc included with demo dll
- The documentation is in web though, maybe will be included after buying the licence.
- slower than any component I’ve seen
- 200ms-250ms for the trivial testcase. This is 4-6 times slower than other components I’ve tested. Uh-oh, this is no small difference.
- Some weird things in API
- prefixes, like “xl”, “mso”, “H”, “V”. This smells of bad style.
- interfaces & factories for everything. Seems unneccessary complex design for simple things. Debugging and code readability suffers because of actual class hiding.
- Lots of releases.
- started in 2006, but since the start of 2009 there has been 19 releases, including sometimes with just 1 day apart. They are either really fast at responding to bug notices or there are quality problems. Not sure which.
- Uncertainty for demo vs licenced version
- No information if/how the demo version and registered assemblies differ or how licence existance is verified at runtime, does the assembly remain the same, etc.