Creating add-ins for Clear Office

by clearoffice 30. October 2009 07:19

The functions accessible from worksheet formulas are implemented as public static functions in special assemblies also called add-in.
Spreadsheet Clear Office comes with two add-ins:

  • The standard add-in (Office.Spreadsheet.StandardAddIn.dll) provides ”must have”  functions such as SUM, OR and LOWER
  •  the Analysis Toolpak add-in (Office.Spreadsheet.AnalysisToolpak.dll) contains more advanced functions such as ACCRINT, ISEVEN and PRICEDISC

By default, spreadsheet document have access only to these two add-ins but you can write your own add-in as well. The first step is create a .NET assembly with the appropriate settings. The second step is to make it accessible to spreadsheet document.
Add-in functions must verify the following:

  • They must be marked as public and static.
  • The containing class must be public and annotated with the [AddInFunctions] custom attribute.

Spreadsheet document discover add-ins through a SpreadsheetContext. By default, the spreadsheet context contains only the two built-in add-ins but you can create your own context with additional add-ins. If you do so, make sure you also add the built-in add-ins as well:

AddIn addIn1 = new AddIn(typeof (Office.Spreadsheet.StandardAddIn.LogicalFunctions).Assembly);
AddIn addIn2 = new AddIn(typeof (Office.Spreadsheet.AnalysisToolPak.DateFunctions).Assembly);
AddIn addIn3 = new AddIn(typeof (CustomSpreadsheetFunctions.MyFunctions).Assembly);
SpreadsheetContext context = new SpreadsheetContext(new AddIn[] {addIn1, addIn2, addIn3});


Once you have created your context, pass it to the spreadsheet document:

SpreadsheetDocument document = SpreadsheetDocument.Create(context);

Two samples demonstrate how to create and use add-ins: CustomSpreadsheetFunctions contains a custom add-in while HostCustomSpreadsheetFunctions uses this add-in.
If you decide to write your own add-in, you should make sure you avoid infinite loops and stack overflows as they would freeze the spreadsheet.

Tags:

Where are the samples?

by clearoffice 30. October 2009 07:18

The Spreadsheet comes with samples they are installed in a different directory. While the reference assemblies are installed in <Program Files>\Reference Assemblies\Clear Office, you will find the samples in <Documents>\Clear Office\Samples.

Tags:

The October CTP is out

by clearoffice 30. October 2009 07:17

This version contains better biff support.
If everything goes as scheduled, this should be last preview before the  1.0 release. If you have find any bug, please send an email to support@clearoffice.com. As always, bug reports are greatly appreciated.
This version also contains a first look at Office.Word. Office.Word.dll is still under development and may change substantially before it reaches 1.0 status. In other words, don’t panic if you see bugs.

Tags:

Opening legacy xls files

by clearoffice 30. October 2009 07:15

Does Clear Spreadsheet support legacy .xls file?
Yes
From the spreadsheet, simply select a file with an xls extension. Clear Spreadsheet will automatically convert it. You can then save to xlsx (Office 12 format).
Developers can open xls document by using the BiffFormat class.

BiffFormat format = new BiffFormat();
SpreadsheetDocument document = format.Open (xlsFileName);

Biff stands for “Binary interchange file format” - the technical name given by Microsoft.
All the code for Biff resides in a separate assembly:  Office.Spreadsheet.Formats.Biff.dll. This way, you can remove this assembly from your application to make it “legacy free”.
Also, you can open csv files (comma separated values):

CsvFormat format = new CsvFormat();
SpreadsheetDocument document = format.Open (csvFlieName);

And tsv files (tab separated values):

CsvFormat format = new CsvFormat();
SpreadsheetDocument document = format.Open (csvFlieName);

 

Tags:

Performance, performance and performance

by clearoffice 27. October 2009 03:55

One of the great benefits of using .NET everywhere is performance.

For example, consider the following code snippet.

        private static void TestMicrosoftExcel()
        {
            var xl = new ApplicationClass();
            Workbook wb = xl.Workbooks.Add(Missing.Value);
            var ws = (Worksheet) wb.Worksheets.Add(Missing.Value, Missing.Value, Missing.Value, Missing.Value);
            for (int i = 1; i < 500; i++)
                for (int j = 1; j < 100; j++)
                    ws.Cells[i, j] = 123;
            wb.SaveAs(@"c:\temp\xls1.xlsx", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                      XlSaveAsAccessMode.xlShared, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                      Missing.Value);
        }

It creates a simple spreadsheet with 500 * 100 = 50000 values.

Problem is, it takes 2 minutes to run.

Let's write the equivalent with Clear Spreadsheet:

        private static void TestClearSpreadsheet()
        {
            SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create();
            var worksheet = (Office.Spreadsheet.Worksheet) spreadsheetDocument.Workbook.Sheets[0];
            for (int i = 1; i < 500; i++)
                for (int j = 1; j < 100; j++)
                    worksheet[i, j].Value = 123;
            spreadsheetDocument.SaveAs(@"c:\temp\xls2.xlsx");
        }

Not only is it somewhat more elegant, it is also faster: 4 seconds.

Recap:

Microsoft Excel: 120 seconds

Clear Spreadsheet: 4 seconds

Try it for yourself!

Tags:

The september CTP is now available

by clearoffice 1. October 2009 06:22

The September Community Technical Preview (CTP) is now ready for download at www.clearoffice.com/download.html
This version includes the following improvements:

  • Support for array formulas

It is now possible to enter formulas such as “SUM(A1:A3*B1:B3)”. The input mechanism is similar to Excel: To enter a regular formula, press “Enter”; to enter an array formula, press Control+Shift+Enter.

  • Better BIFF support

BIFF is the legacy binary format (with the .xls extension). Clear Office can now open most .xls files.

  • A new WorkbookControl

The spreadsheet framework includes a new control: WorkbookControl.  The goal behind the WorkbookControl is to make workbook hosting in your application super easy. Once you have added the reference to the Clear Office assemblies, simply insert a <spreadsheet:WorkbookControl /> tag in your XAML and the Workbook will be visible in the designer.

  • Better auto fill

Auto fill has been improved. In particular, auto fill now works on time values. For example, if a sheet contains 9 AM, auto fill will yield 10 AM, 11 AM, etc


As usual, contact support@clearoffice.com for any question or problem.