C# Excel.Interop Detecting a Sort Action - c#

I have looked at the various levels(application, workbook, and worksheet) of the Excel.Interop libraries to find out how to detect a user sorting data. I have created a class that instantiates an application, workbook, and worksheet. The program has data piped in from another application and then adds it to a worksheet. I am using .NET 4.5, C# compiler version 4.0, and have been testing with Excel 2013 if that makes a difference.
I can detect cell changes and calculation events but neither of those events fire when a column is sorted. I believed that it should work after reading this article.
After having that fail for me, I looked into the table update event but I had no luck. There error I received was along the lines of, "the handler does not exist in the Microsoft.Office.Interop.Excel namespace, are you missing an assembly. I don't think this is the right direction I need to go but I was attempting to see if it would suit my needs.
Using any other method besides the Excel Interop method might set me back a few weeks.
Is there something I am missing in regards to the table update event handler or perhaps the sort event itself?

Related

Using ProtectContents on IWorksheetin Spreadsheetgear

I've a workbook object in which I'm using excel formulas in certain cells.
I'm programmtically setting the value for ProtectContents on IWorksheet object to turn the readonly mode on those cells on and off.
1.When the value of ProtectContents is set to true, I see that all the cells are in read-only mode as expected but the cell (which use excel formula) value show up as #NAME?.Is this how it works in Spreadsheetgear?
2.And when the ProtectContents is set back to false,I see all those cells which use formula still show value as as #NAME? but they are editable as expected.But wondering why are those cells values not getting evaluated??
Please advise.
Thanks for your help.
There should not be any correlation between #NAME? errors and the state of worksheet protection. #NAME? errors can occur for a number of reasons but without more details on your particular case it's impossible to say why you are seeing this.
One common reason you might see this in SpreadsheetGear (and I presume not in Excel itself?) is because the formulas in these problematic cells either directly or indirectly depend on a User Defined Function (UDF) in the VBA portion of your workbook, from an external XLL add-in, etc. SpreadsheetGear does not support executing UDFs via VBA or XLLs, so such functions would evaluate to #NAME?.
SpreadsheetGear does support implementing your own Custom Functions in your .NET application via the SpreadsheetGear.CustomFunctions.Function class and its Evaluate(...) method. If you discover the above being the cause, you could implement your own Function to make these cells correctly calculate. I'd provide sample code but I'm going out on a limb in the first place mentioning this as being the underlying cause. Update your question with more specifics and I can update mine accordingly if needed.

Change Tracking in Excel

To avoid polling MS Excel file, I am looking something similar to SqlDependency class which can alert the application about changes in the file.
Also, is there something similar like SQL Change Tracking feature, for MS Excel (2010 or above)?
My sole purpose is to display excel file contents in GridView and update GridView with the newly inserted rows in excel.
I went through ListObject.Change Event, but it works for a selected range and returns the cells which are changed. But I am in need to newly inserted or deleted rows (no cell-editing or updating required).
You can subscribe to the Workbook.SheetChanged event for changes to any sheet in the workbook, or the Worksheet.Change event for changes to a particular sheet.
Excel has no concept of "adding" or "deleting" rows like SQL, so there's no way to pinpoint to just those types of events - you'll have to determine what changed in your event handler and decide if you want to do anything about it or not.
Or stop using Excel as a database :)

Track method input and input of methods of running dll using c#

I have a need to record parameter values of methods been called with in application. A kind of log.
I don't want to touch the code of the running application dll, by adding a row in each method to log it.
Is there any way I can some kind mechanism to capture input/ouput paramert values, by inserting logger code into the dll without touching the main source code? i am trying to achive this in C#
You will achieve this by using AOP. Refer this link for more information.
Also have a look into this stackoverflow link.

Inserting page break using Aspose.cell OR Aspose.Excel

We have a reporting project where in we use the .NET framework to create excel reports on the fly. The different components that are used are System Namespace, Aspose.Cell and Aspose.Excel
We have a report where we execute a certain set of command in a loop. After each loop execution we need to insert a page break. Currently, we use System.Environment to insert line breaks, but I don't see any similar method for page break. Also, I read some where that the Aspose.cell latest version supports page break, but we are using version 4.7.1.0
Can someone advise me on how this can be done?
Although I have ever never worked with Aspose before, I did a quick search and found that there was a VerticalPageBreak object in the object model as shown on the website:
Each Worksheet object contains a VerticalPageBreakCollection object. A VerticalPageBreak object is used to create a vertical page break in the worksheet.
The best way to insert page breaks seems to be by using the VerticalPageBreak Class:
excel.Worksheets[0].VerticalPageBreaks.Add("G5");
Here is a reference to the VerticalPageBreak Class.
This should take care of vertical page breaks.

C# How can I create and print a document?

I have a timetable in memory, and need to be able to print it out.
The timetable will likely be many pages, each page will look quite similar:
A grid of cells, across the horizontal axis is time, and along the vertical axis is entities. Cell x, y will contain the allocation of a particular job to entity x at timeslot y.
I'm looking at the System.Drawing.Printing.PrintDocument class but it's incredibly cumbersome. I need to set an event handler to the PrintDocument.PrintPage, yet there doesn't appear to be any way to get the page number from the PrintPageEventArgs?
I just want to construct my document and call some Print() function. I suppose if I could get the page number within the event handler, I could construct the page layout on the fly with e.Graphics and GDI.
I could potentially even put together a HTML page using tables and print that - if I could somehow control what prints on what page?
Is there a better way to construct and print documents in C#?
The target machines do have Office installed, but they're all different versions and I've had lots of trouble getting correct versions of the .Net/Office interop library to work with them.
Edit: I could potentially even create a temporary LaTeX file on the fly and compile it, then print it. This seems like a good solution, except that the target machines are locked and the users can't install new software, hence I would need to bundle the LaTeX compiler with my program, and my compiler is almost 300MB.
Sounds to me like you're giving up too soon. Handling the PrintPage event isn't that difficult and since the event is raised sequentially, all you have to do is keep a page counter in that event. That's how I've done it in the past with MetaFile images (printing Reporting Services reports through a web service call).
I build a similar tool by using the Microsoft Chart Controls, easy to use.
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=130f7986-bf49-4fe5-9ca8-910ae6ea442c&displaylang=en
If you can save it to a file, you can use this here,
Print images c#.net

Categories