Question

I'm writing a Microsoft excel task pane app for the first time. I understand the JavaScript API that Microsoft has created to bind to different cells.

I do not see anything within the JavaScript API that would allow you to do common functions like:

  1. Changing the active sheet
  2. Creating new sheets
  3. Changing cell colors, fonts, sizes, borders, etc.

I'm wondering how to accomplish these functions... Do I have to incorporate a VB file into my app, and if so, how?

Thanks!!

Was it helpful?

Solution

You are correct.

The creation of new sheets, changing formatting should be left either to the user or you could provide a workbook for them that would represent a templated layout with styling.

With regards changing the active sheet, it's likely you won't need to do this. The API provides bindings that enable you to attach to cells, matrices and tables anywhere in the workbook and these give two-way bindings with the data.

If you describe the scenario you envisage, I could have a go at providing some pointers.

OTHER TIPS

You still can't create new sheets, but you can now format cells.

Here is an example format function.
function Format1() { var tableData = new Office.TableData(); Office.select("bindings#MyTableXXX").setFormatsAsync( [

                //row 1
                { cells: { row: 0, column: 2 }, format: { alignHorizontal: "right", fontSize: 15 } },

                //row 2
                { cells: { row: 1, column: 0 }, format: { numberFormat: "dd-mmm-yy", fontStyle: "bold" } }, 
                { cells: { row: 1, column: 1 }, format: { fontColor: "red", fontStyle: "bold", numberFormat: "#,###.00", borderColor: "blue" } },

                //row 3
                { cells: { row: 2 }, format: { height: 30 } },

                //Whole table: 'Office.Table.All', 'Office.Table.Data' (no headers) and 'Office.Table.Headers'
                { cells: Office.Table.All, format: { borderStyle: "dotted" } },

                ],
        function (asyncResult) {

            //NOW DO OUTPUT OR ERROR - add your own output method here
            if (asyncResult.status === "failed") {
                writeToPage('Error Format1: ' + asyncResult.error.message, 3);
            }
            else {
                writeToPage('Table cell formats changed', 1);
            }
        });
}

For more information you can see http://microsoft-office-add-ins.com

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top