Get values and formulas of a workbook by JavaScript API for Excel 2013? - ms-office

I often need to collect the values and formulas of the usedRange of all the worksheets. I am wondering how to do this by JavaScript API for Excel 2013.
It seems that the only way to get/read data is via binding. There are for example MatrixBindings and TableBindings. But I don't see how to bind to a fixed area (let's say A1:Z1000 of Sheet1).
Could anyone help?

Here's a way to get the values in a named range in Excel 2013:
var myBindings = Office.context.document.bindings;
myBindings.addFromNamedItemAsync("Sheet1!A1:Z1000", "matrix", {}, function (asyncResult) {
asyncResult.value.getDataAsync(function (asyncResult2) {
console.log(asyncResult2.value);
});
});
There isn't any way to get the formulas in 2013.
I should note the smaller API set available for Excel 2013 isn't really designed for getting the entire contents of sheets, but the above code will still work for this narrow case.
-Michael Saunders (Program Manager for add-ins in Office)

Related

Client has Excel 2019, I have Excel 365. Dropdowns of spilled arrays don't work for client

The spreadsheet I've created has multiple dependent dropdowns that reference spilled arrays. Specifically, the dropdowns reference a cells that each use Filter() and Sort().
The client has Excel 2019 and reports that the dropdowns don't function. I've made sure that In-cell Dropdown is selected in Validation. I've ensured File>Options>Advanced>Display Options for this workbook has "For objects, show:" All is selected.
I'm aware that I could create a combobox to replicate the function of the dropdown, but I'm under the assumption that all other cells in the spreadsheet that use Filter() and Sort() wouldn't work.
Is that a correct assumption to make? Is there a way to have these functions work in Excel 2019? If the file were uploaded to SharePoint, would that allow the client to use the file?
Thanks for your consideration. This is my first post. I hope it was clear. If not, I will try to further clarify.
Thanks again.
The client uploaded the file to SharePoint and was able to use the file without issue. This solved the issue of the dependent dropdowns not functioning, and also made sure the rest of the file worked correctly with the Filter() and Sort() functions creating spilled arrays.

Inserting OMML formulas into Excel sheet via office.js

Is it possible to add a mathematical formula (not an Excel equation) of OMML type into an Excel sheet via office.js? I know you can add them manually by using "Insert" / "Equation" ("Equation" just below "Symbol"), which results in an OMML formula (an <m:oMath> element in the Excel sheet XML source).
Thanks Stefan,
Unfortunately, Office JS Excel API currently doesn't support OMML type. Therefore, I would suggest that you could submit the request and upvote this request at uservoice. https://officespdev.uservoice.com/forums/224641-feature-requests-and-feedback?category_id=163563

How to retrieve excel cell formatting properties in app-for-office add-in

I'm starting to play around with apps for office - specifically working on a task-pane app for excel that needs to retrieve cell formatting properties from a range.
It is possible to set properties in a bound table with
bindingObj.setFormatsAsync(cellFormat [,options] , callback);
but an equivalent getFormatsAsync() doesn't appear to exist. Anybody know how to do this?

Is there a way in SpreadsheetML to force Excel to recalculate formulas (and other dependencies) when document is opened?

As far as I understand cells with formulas in Microsoft Office Excel can contain calculated values when serialized and saved in Office Open XML formats (specifically SpreadsheetML). This most likely applies to other types of dependencies and functions of values from other cells (like charts, pivot tables, etc.). I most likely do something wrong, but when processing this XML documents (SpreadsheetML) by external tools, that do not use any .Net components or similar APIs provided by MS, but just directly manipulating XML, I get into a problem that when I modify some content of one of worksheets Excel will still use last generated values in cells containing formulas. So when user opens generated spreadsheet he sees modified data but all the calculated fields are outdated. Now the only thing that I could find (these days) on internet was this:
http://openxmldeveloper.org/discussions/formats/f/14/p/1561/4164.aspx
This is really not a preferable solution especially if it applies to any kind of calculated cells and objects (charts, etc.) as it means partially reimplementing some SpreadsheetML processor when you do not know exactly the structure of all worksheets.
I would hope there would certainly be either an option in Excel or a configuration in one of the SpreadsheetML parts to force recalculations or to mark cells dirty, but I couldn't find one yet.
There is an assumption that scripting would help, but my lack of knowledge of that area didn't brought me to any successful results yet as I'm not sure how to include scripts into SpreadsheetML worksheet. Though I found quite some examples how to trigger recalculation and how to add open event listeners.
The easiest way is to remove the calculated value from the cell (as also noted in the link you provided).
You do not have to know the exact structure of worksheets. Just remove all occurrences of <v>#VALUE!</v> in worksheets/sheet1.xml (so that other functions will not be affected).
press F9 to recalculate all open workbooks
Excel Recalculation
Perhaps your Calculation Mode for the workbook is getting set to manual. Force this mode to Automatic when you open the workbook by setting it to null in the code with the following:
public void SetAutomaticCalculationMode(WorkbookPart workbookPart1)
{
Workbook workbook1 = workbookPart1.Workbook;
CalculationProperties calculationProperties1=workbook1.GetFirstChild<CalculationProperties>();
calculationProperties1.CalculationMode = null;
}
This will correspond to Automatic calculation mode as seen in the Options of Excel 2007 client:

Excel formulas are not being generated by Reporting Services

I'm working on a report for my employer where the end product is a SSRS report, but one that will almost ALWAYS be exported to Excel for further manipulation. In this report, there is a row that is really just a row of calculations based on other cell values.
I've read that Reporting Services can "figure out" Excel formulas, and will generate and insert them where it can so long as your expressions for the cell's value do not contain database field references, only report item references.
Well, I've done this and I'm still not able to get the formulas to come through. I've tried rendering the report every way I could think of, and I've tried modifying the DeviceInfo parameters to include the OmitFormulas option set to False, and still I've come up empty. I've even tried creating a VERY simply table based report with hard-coded values, and even then I don't get formulas.
Here's a sample expression from my report:
=(ReportItems!Balance2.Value + ReportItems!Supply3.Value) - ReportItems!Demand3.Value
My environment is VS 2008 (fully patched/updated) running on SSRS 2008 (not fully patched). I've talked to the server admin, and he says it's running CU1 (I think, can't remember for sure). Our company's Excel is version 2007.
I'm really at my wits end here, so I'm hoping someone out there has dealt with this before and can give me an answer. Thanks!
I have also tried this, the problem here is that SSRS 2008 simply does not support this functionality. It is true that in earlier versions of SSRS it was somewhat supported (2005), however they took that out in the later versions... too bad..
see link:
http://social.msdn.microsoft.com/Forums/en/sqlreportingservices/thread/ddf2f19d-3f70-4bb0-a035-00709ffee2f9
I found a way to do it IF you know the cell addresses, though it's a bit of a hack. In your report, enter the cell formula as a string preceded by an apostrophe, the "this is text" escape character in Excel:
="'=A2+A3"
When you export into Excel the apostrophe will be invisible, but the formula appears as text:
=A2+A3
Now if you do a find/replace and remove the apostrophes (replace with nothing), the formulas will calculate correctly.
SSRS has quite a few limitations when it comes to Excel content. As you mentioned Excel Formulas or even charts for example are rendered as images instead of Excel Charts.
Seeing as you mentioned that you want a report that works in SSRS, but will always be exported to Excel you should really checkout OfficeWriter at http://www.officewriter.com/.
OfficeWriter can integrate with SSRS and will allow you to export a full fidelity Excel document. By that I mean you can have Excel Formulas, not the rendered SSRS formulas, or real Excel charts not the rendered image. These types of things won’t change if your data changes after the file have been rendered and opened by SSRS.
If the “further manipulation” happens by end users then this is great, they can change numbers and the formulas will recalculate and the charts will update.
If the “further manipulation” is programmatic, then you can use OfficeWriters API to continue to manipulate the document.
You may want to give it a look, I hate for you to be on your wits end.
DISCLAIMER: I am one of the developers on OfficeWriter.

Resources