I have a program that uses a dynamically created reports in excel, and prints them out to a pdf. I am having a problem with some of the reports that run for 4-5 hrs. Excel memory usage starts to exceed the system limits, and I can not determine a way of clearing some of the memory without killing the application process. Does anyone have any incite? I can't kill and restart Excel process because my objects, in the Excel Object in C#, need to persist some information. THanks.
First of all, I suggest that you can prepare your data in database first, because the dynamically invoking is really slow.
Just let your excel api application to do the works about display and convert.
Did you try using excel.Visible = true to show the excel UI?
Related
I have an excel spreadsheet that performs complex calculations. I am injecting a value into excel using c#, and then extracting the new value of the calculations in c# also. The problem is the calculation does not happen unless i manually open the excel file and save it.
for example if cell A1 = 1, A2=3 A4=sum(A1+A2)
after updating A1 = 5 via c# the value of A4 is still 4 instead of 8
Is it possible to get the excel file to update without manually opening it? I am currently using EPPplus as interop cannot be run on azure.
Any help would be appreciated even if it's just telling me it's not possible.
Try Spreadsheet Gear. Works great in a server environment as well.
EDIT: The alternative is to use Automation, but I generally advise against it. Too often you end up with memory leaks and crashes.
I have a windows app that opens excel. The user can then decide to save it.
This uses Interop and is very slow when we have over 100 rows. I'm experimenting with EPPlus and see how to save directly to a file. But I don't want to do that, I need to open Excel from the app. So I'm thinking to write out the worksheet using EPPlus (thus saving time) and then copying the whole worksheet into Excel and open it. Does that make sense? Are there examples of this?
First off, I've used EPPlus and it's a great tool.
I'm a little confused by your question, so let me ask some clarifying questions.
Why are you launching excel from your app? Is it to edit some kind of file your program generates, or just random files the user wants to edit?
Once the user is finished editing the file, do you need to read it back into your app? If so, that can also be done with EPPlus.
Once I know more about what exactly you're trying to do, I'll be glad to help you.
--John
I created an Excel Interop app that is used by a few internal users.
One noted that my app doesn't work right when she is simultaneously using Excel; at first I thought this was a coincidence/superstition, but then I found a reference that indicates that running Excel at the same time as an Excel Interop app may indeed prove problamatic.
Is this really so - should I advise them all to quit Excel before using my app?
I have 1 routine that is structured like this:
C# console C opens xl workbook A
C then runs A's macro M which saves the target worksheet as a PDF using VBA
C then uses PDFsharp to encrypt the PDF file.
C then emails this file.
Currently this procedure is for one report so no problem if the architecture isn't textbook.
I imagine in the future there may be many target worksheets in many different workbooks all going to lots of different recipients. If this is the case then Step 2 will need to go as I will not want to have to copy this VBA code into every target workbook! The only alternative I can imagine as my experience is limited is the following:
Take the current VBA code out of Excel and move it into C using a reference to Excel.Interops
Assuming that the target worksheets are the finished article i.e. no further manipulation is required before going to PDF is the above the correct approach for moving this step out of VBA and into the console, or should I create the PDF using a different library?
The least-effort option is moving the code from the worksheet into a VBA add-in by deleting all the sheets/data out and then use 'save as' to turn the workbook into an add-in which you can then load into excel and will be available all the time. Depending on how you've written it some changes may be required but they won't be as big as a port to c#.
That said, having the code all in one place will make the whole process easier to look after in the future. Plus you've already got C# code automating excel to fire the VBA so it may be better to do it now if you have time.
I am new to C# and VS. I am working on a problem in which I need to make an excel ribbon, that provides me with the functionality of passing column values in a sheet to another program that we have developed that does data visualization. I need some ideas on how to get started and how will it all work. For the same I needed some guidance. Any help on how to proceed will be appreciated.
Thanks.
Arun
I would think you'll have to make your visualization program able to start with one or two parameters. I would have the excel plugin save the selection to the temp folder in whichever format your visualization program uses, and do a process.start() on your visualization program, with an argument pointing at the just stored data. From there on your can read the stored data in the temp folder and display it.
Perhaps you could use copy and paste via the operating system clipboard?