Excel VSTO Addin Using ChromiumFX Issue - excel

I'm trying to invoke browser control in a Window Form using ChromiumFX framework in the Excel VSTO Addin.
The excel application throws the following alerts and another excel instance gets started.
Sorry, we couldn't find Files\Microsoft.xlsx. Is is possible it was removed, renamed of deleted ?
Sorry, we couldn't find Office\root\Office16\debug.log. Is is possible it was removed, renamed of deleted ?
Although I’m able to load the URL in the Web Browser control but i get the above errors multiple time and every time another instance of excel gets initiated.
I’m invoking the following piece of code after which the alerts start appearing.
var assemblyDir = System.IO.Path.GetDirectoryName(new System.Uri(System.Reflection.Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath);
Environment.CurrentDirectory = System.IO.Path.Combine(assemblyDir, #".");
if (CfxRuntime.PlatformArch == CfxPlatformArch.x64)
CfxRuntime.LibCefDirPath = #"cef\Release64";
else
CfxRuntime.LibCefDirPath = #"cef\Release";
Chromium.WebBrowser.ChromiumWebBrowser.OnBeforeCfxInitialize += ChromiumWebBrowser_OnBeforeCfxInitialize;
ChromiumWebBrowser.OnBeforeCommandLineProcessing += ChromiumWebBrowser_OnBeforeCommandLineProcessing;
Chromium.WebBrowser.ChromiumWebBrowser.Initialize();
Any suggestions on what i might be doing wrong ? Or what piece of code i’m missing ?

Related

Excel JS API - SettingCollection not persisting

I'm trying to update my Excel add-in to use the workbook SettingCollection instead of the Office.context.document.settings object. The documentation seems to suggest they are functionally equivalent, but with document.settings I can call saveAsync() and see my data persisted (in the PropertyBag in a webextensions.xml).
With ctx.workbook.settings.add('key', 'value'), I can get the settings and get them in the current session, but they don't get added to the webextensions.xml and aren't available on the next open of the add-in.
Is there a version of saveAsync for workbook settings that I'm missing? I assumed context.sync would take care of it, but I haven't had any luck.
Edit: I figured out what was causing my initial issue, but the problem is still there. When I close the browser tab with Excel Online and re-open it with my add-in, the settings are not persisting. Nothing is getting added to webextensions.xml.
Here is an example Excel.run()
window.Excel.run(async ctx => {
ctx.workbook.settings.add('hello', 'world');
await ctx.sync();
let setting = ctx.workbook.settings.getItemOrNullObject('hello');
setting.load('value');
await ctx.sync();
console.log(setting.value);
});
The setting 'hello' sets and exists the next if I relaunch my add-in, but not if I close the file and open my add-in.
there is a bug with the Excel rich API for settings, can you please try the Shared API flavor as a workaround in the meantime...
function createSetting() {
Office.context.document.settings.set("Foo", "bar");
Office.context.document.settings.saveAsync();
}
function readSetting() {
console.log(Office.context.document.settings.get("Foo"));
}

Epplus xlsx file won't open in libreoffice after downloading, but will open in excel

I'm generating an EEPlus .xlsx file that the user can download after clicking a button. It won't open on my Win8 machine with LibreOffice 4.4.1.2, but it will open on my coworkers Win8 machine using Excel 2013.
I get an error saying the file is corrupt and needs to be repaired, and when I try to repair it, it says it's unable to. My coworker also gets this error but is able to repair it and view the file.
Here's the relevant code for the creation of the downloadable version:
MemoryStream ms = DataTableToExcelXlsx(dt, "Report");
ms.Position = 0;
ms.WriteTo(Response.OutputStream);
Response.ContentType="application/vnd.openxmlformatsofficedocument.spreadsheetml.sheet";
Response.AddHeader("Content-Disposition", "attachment;filename=DataTable.xlsx");
Response.StatusCode = 200;
Now the weird part is that I'm also generating an xlsx file that is attached to an email, and it opens just fine. Neither me nor my coworker receive the error when opening the file attached to to the email.
Relevant code for the creation of the email attached version:
MemoryStream ms = DataTableToExcelXlsx(dtReportData, sReportTitle);
ms.Position = 0;
MailMessage mail = new MailMessage("you#yourcompany.com", sReportEmails);
using (SmtpClient client = new SmtpClient())
{
mail.Subject = "Mixer - Test Scheduler Task Execute.";
mail.Body = string.Format("The following report is executing. ReportSettings Id: {0}", reportSettingsId);
mail.Attachments.Add(new Attachment(ms, sReportTitle + ".xlsx", "application/vnd.ms-excel"));
client.Send(mail);
}
I've also tried using the vnd.ms-excel MIME type for the downloadable version and that didn't work, so I'm at a loss as to why this is happening.
I would have liked to answer this as a comment, but no reputation yet, or whatsoever.
Firstly, Why dont you try to use this content type?
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Currently, it does seem to be wrong. Please see as well this post, in which correct mime types are defined.
Try making a unit test or command line app that creates the xlsx to your local hard drive (avoiding all the the web Response stuff). Then see if the error shows up in that xlsx.
If it does then it is the code that create the file. Post it up and we can take a look.
If it does not then something is up with the response settings. Maybe in the disposition? Here I have an Response stream that I know works: Open ExcelPackage Object with Excel application without saving it on local file path

EXCEL.EXE Running even after i use excelObj.Quit(); in activexscripts

Since, I could not find any satifying answer on the web for this question, I put forth it in Stackoverflow. I use activexscript to manipulate Excel, Outlook. But, even after I runexcelobj.Quit() at the end, I see an EXCEL.EXE still running in the task manager.
I tried using excelobj.Application.Quit() (as mentioned by some post in stackoverflow)also did not resolve the problem.
Can somebody help me with this??
Here's one way the application goes away in JScript:
// WScript.CreateObject for cscript.exe or wscript.exe
var excel = new ActiveXObject("Excel.Application");
// ...
excel.Quit();
// null out EVERY reference to Excel objects
excel = null;
CollectGarbage();

Add a footer to an existing OpenXML spreadsheet

EDIT: There's a further detail I left out with my original post. The program is using a template stream rather than a concrete template for the ".Open" command. The template stream gets initialized with this code block:
public void Initialize(Stream templateStream)
{
spreadsheet = SpreadsheetDocument.Open(templateStream, true);
}
I'm still researching this, but does anyone know the implications of using a stream for the HeaderFooter object in OpenXML?
I'm new to OpenXML and still in the process of reading and learning what I can of this massive SDK. I've inherited a C# MVC.NET program that uses OpenXML to display information on an Excel spreadsheet and all of that is working, but I now need to add a footer to the same spreadsheet and I'm hitting some brick walls in my OpenXML knowledge.
I put the footer information I wanted into the spreadsheet, opened it up with the Open XML SDK Productivity Tool and found this code under <.x:oddFooter(OddFooter):
// Creates an OddFooter instance and adds its children.
public OddFooter GenerateOddFooter()
{
OddFooter oddFooter1 = new OddFooter();
oddFooter1.Text = "&L&\"Times New Roman,Regular\"Page &P of &N&C&\"Times New Roman,Regular\"Generated On: <Date/Time> Central&R&\"Times New Roman,Regular\"Report";
return oddFooter1;
}
And this code one level up under <>x:headerFooter(OddFooter):
// Creates an HeaderFooter instance and adds its children.
public HeaderFooter GenerateHeaderFooter()
{
HeaderFooter headerFooter1 = new HeaderFooter();
OddFooter oddFooter1 = new OddFooter();
oddFooter1.Text = "&L&\"Times New Roman,Regular\"Page &P of &N&C&\"Times New Roman,Regular\"Generated On: <Date/Time> Central&R&\"Times New Roman,Regular\"Report";
headerFooter1.Append(oddFooter1);
return headerFooter1;
}
Now I of course need to append the footer info somewhere, and this is where I'm stuck. In <>x:worksheet(Worksheet) I see this line of code:
worksheet1.Append(headerFooter1);
This looked easy enough, but when I looked back at the application code I found no worksheet object to append to. I thought I was close with the following line of code:
spreadsheet.WorkbookPart.Workbook.Append(headerFooter1);
but this yielded nothing. In the application I see a SpreadsheetDocument object and references to OpenXMLParts... do I need to get a spreadsheet part to append to? Or do I need to take a different approach with a Spreadsheet versus a worksheet object? Do I need to materialize the current worksheet and then append?
I have a feeling this has an easy solution, but as I said I'm still learning the SDK.
Thank you!
For those who don't know about the productivity tool, it is included with the SDK and can be downloaded from https://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=5124
On my 64 bit machine, the install path to the tool was:
"C:\Program Files (x86)\Open XML SDK\V2.0\tool\OpenXmlSdkTool.exe"
You should be able to manually add a footer to a spreadsheet, and open it up with the tool and see the exact C# required to create the entire spreadsheet, including the footer. You can then remove the parts of the code that are unnecessary, like some of the styles that are automatically added.

Why does my SharePoint workflow fail when the client is running Vista or Windows 7?

I have a similar situation to this question.
I have a custom sequential SharePoint workflow, deleoped in Visual Studio 2008. It is associated with an InfoPath form submitted to a form library. It is configured to automatically start when an item is created.
It works sometimes. Sometimes it just fails to start.
Just like the question linked above, I checked in the debugger, and the issue is that the InfoPath fields published as columns in the library are empty when the workflow fires. (I access the fields with workflowProperties.Item["fieldName"].) But there appears to be a race condition, as those fields actually show up in the library view, and if I terminate the failed workflow and restart it manually, it works fine!
After a lot of head-scratching and testing, I've determined that the workflow will start successfully if the user is running any version of IE on Windows XP, but it fails if the same user submits the same form data from a Vista or Windows 7 client machine.
Does anyone have any idea why this is happening?
I have used another solution which will only wait until InfoPath property is available (or max 60 seconds):
public SPWorkflowActivationProperties workflowProperties =
new SPWorkflowActivationProperties();
private void onOrderFormWorkflowActivated_Invoked(object sender, ExternalDataEventArgs e)
{
SPListItem workflowItem;
workflowItem = workflowProperties.List.GetItemById(workflowProperties.ItemId);
int waited = 0;
int maxWait = 60000; // Max wait time in ms
while (workflowItem["fieldName"] == null && (waited < maxWait))
{
System.Threading.Thread.Sleep(1);
waited ++;
workflowItem = workflowProperties.List.GetItemById(workflowProperties.ItemId);
}
// For testing: Write delay time in Workflow History Event
SPWorkflow.CreateHistoryEvent(
workflowProperties.Web,
workflowProperties.WorkflowId,
(int)SPWorkflowHistoryEventType.WorkflowComment,
workflowProperties.OriginatorUser, TimeSpan.Zero,
waited.ToString() + " ms", "Waiting time", "");
}
workflowProperties.Item will never get the InfoPath property in the code above.
workflowProperties.List.GetItemById(workflowProperties.ItemId) will after some delay.
This occurs due to the fact that Vista/7 saves InfoPath forms through WebDAV, however XP uses another protocol (sorry, can't remember at the time). SharePoint catches the "ItemAdded" event before the file is actually uploaded (that is, the item is already created, but file upload is currently in progress).
What you can do for a workaround is to add a dealay activity and wait for 10 seconds as the first thing in your workflow (will actually be longer than ten seconds due to the way workflows are built in SPPS). This way the upload will already have ended when you perform to read the item. To inform the users about what's happening, you can add a "logToHistoryList" activity before the delay.

Resources