Get Array Formula value for cell in Excel-DNA - c#

I have an Excel DNA Ribbon and a set of formulae that return arrays.
I'd like to add a button on the ribbon which expands an array formula out to the size of the data - much like this: http://excel-dna.net/2011/01/30/resizing-excel-udf-result-arrays/ but on the click of a button rather than when the UDF is run.
I have a reference to the cell:
ExcelAsyncUtil.QueueAsMacro(
() =>
{
ExcelReference current = XlCall.Excel(XlCall.xlfActiveCell) as ExcelReference;
});
but don't know what to do from here. If I try to use object value = current.GetValue(); I just get the display value of the individual cell.
I tried to access the Formula but I don't want to have to evaluate every parameter individually.
Any ideas would be gratefully received.

From the ribbon handler, it's probably easier to do this using the COM object model. Perhaps this post has some VBA that would give you a start: https://newtonexcelbach.wordpress.com/2015/04/14/re-sizing-array-functions/
In your Excel-DNA add-in, you get the root Application object with a call to ExcelDnaUtil.Application.

Related

EPPLUS: how to check if all cell are valid?

I'm using Excel's data validation lists, checking if the cell value is into a dynamic range (the cell values of another column).
The problem is that if I add a value into the source range (eg. "A"), I can input that value on the cell with data validation. But then, if I change the source (eg from "A" to "B") the cell with data validation is still "A".
In Excel there's a button that sets a red circle around invalid data, but client does not always check if everything is good.
Can I perform that check with EPPLUS?
The documentation doesn't suggest that this check can be performed by EPPlus:
https://www.epplussoftware.com/Developers/Features mentions "Create, read, modify, delete Data validations" and links to sample code in their wiki, which is all about designing the sheet and inspecting its design, no content validation.
I've searched the source code and looked at ExcelDataValidation.cs and its various sub-types. Their "Validate" methods only check if the validation is properly defined according to Excel's rules.
To achieve what you're asking for, you'll have to use EPPlus to get the validation from the cell, interpret it depending on its type and evaluate the cell content. There is an example that touches some of the cases and could give you an idea where this is heading.

How can you fill a table cell using Selenium?

I'm trying to fill a table using the selenium drivers and all the documentations I could find only shows how to retrieve data from the cells. I'm able to access my table cells using:
var rows = Driver.FindElement(By.Id("Products")).FindElements(By.XPath("id('Products')/tbody/tr"));
var cells = tableRows[1].FindElements(By.XPath("td"));
But I couldn't find any way to update the data that's in it. The "Text" property only has a Get method and the SendKeys() function doesn't work. How can I edit the cell's value?
As a side note, my cell contains an html "input", I've tried to access it with the FindElement function of the cell but for some reasons it cannot find it.
Generally speaking, SendKeys should work if the cell indeed contains the input element. But because you're also saying that you fail to find the input element, I suspect that the input element does not exist in each cell all the time. You should probably first click on the cell in order for the input element to appear on that cell. You should be able to verify it using the Dev Tools if you inspect the element before clicking it.
IWebElement doesn't provide a method to change text, but you could use a little bit of JS - something little like :
((IJavaScriptExecutor)Driver).ExecuteScript("document.getElementByXXXXX.innerHTML = "VALUE";");
https://seleniumhq.github.io/selenium/docs/api/dotnet/html/M_OpenQA_Selenium_IJavaScriptExecutor_ExecuteScript.htm

Evaluating formula from csv using EPPlus

To load formulas in a range I've used this method
ws1.Cells["B4:D4"].LoadFromText($"={con_Fu_LF},={con_Un_LF},={con_Fo_LF}");
and to evaluate I've called
ws1.Cells["B4:D4"].Calculate();
Opening the workbook I see strings in that range, for example in B4:
='Fu-LF'!F6841+'Fu-LF'!K6841
these are evaluated when I click on formula bar selecting a cell and press enter.
I want these to be evaluated automatically, how to do?
LoadFromText sets the cell .Value property. But you need to set the .Formula like this:
ws.Cells["B4"].Formula = $"={con_Fu_LF}";
It works with the spacebar trick because that is Excel itself detecting that it "looks" like a formula and automatically setting it.
There is no way to do it that doesnt require you to loop through the cells/strings manually.

Excel Interop XSD and XPath

I am succesfully binding XSD to Excel using Interop (C#) and XPath.
However, there is one thing I am unable to succeed at.
When using the Developer toolbar in Excel it is possible to bind an entire XSD to a cell. This creates some sort of merged row in the Excel sheet for all the attributes in the node. When expanding this row one can receive multiple values for each attribute from XML.
I would like to have this behaviour as well in the code I wrote, but so far I have only been able to map attributes sepperatly to a single cell.
So the question is:
Can I bind an entire Node to a cell using interop? Instead of binding the attributes sepperatly.
Thanks!
Edit:
This is a screenshot of what I have now:
http://imageshack.us/photo/my-images/193/badl.png/
And this is a screenshot of what I want (Manually done in Excel):
http://imageshack.us/photo/my-images/406/goodu.png/
I'm unsure on your particular case, but if you're using Excel interop then you can use a little trick.
Create a new macro (in Excel 2007 its View->Macro).
Perform the manual action.
Stop the macro.
Then Step-into the macro and see what the VBA code looks like, will give you a starting point
on how to do it with Interop.
It seems that I have figured out what to do.
I was creating a List object for each cell and then binding it using xpath.
What I had to do was span the List object over multiple columns (using a range object), and then bind each cell in the list using xpath.

Change datasource for chart in Word c#

I'm trying to create a word-document on the fly and in there I'm suppose to have a chart. For that, I have
doc.InlineShapes.AddChart(Microsoft.Office.Core.XlChartType.xlCylinderCol, ref oRange);
However that opens Excel, reads data from some default data source of some kind and closes again.
How do I control this chart and choose the data source, and labels on axis?
This helped me a lot when I had the exact same question -
How to add graph in word
The example shows adding a graph as an OLE object, but the AddChart method works in a very similar manner. To add a graph to a Range, you would essentially do
InlineShape objShape = doc.InlineShapes.AddChart(XlChartType.xlCylinderCol, ref oRange);
To get access to the relevant objects
Chart objChart = objShape.Chart;
Workbook book = objChart.ChartData.Workbook;
Worksheet dataSheet = book.Worksheets["Sheet1"];
Now you can manipulate all the properties on the Chart and Datasheet like Axes, Data, Colors etc.
Another helpful tip, if you are not sure how to find something in the API, fire up Excel and start Record Macro to capture the changes you want, and then look at the Macro code. Looking at the Recorded Macros usually sets me on the right path when I know how to do something using the UI but not in the API.

Categories

Resources