Excel Interop XSD and XPath - c#

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.

Related

C# - Excel API - Determining parent/child relationship between Rows

I am exporting a smartsheet, and in order to maintain the hierarchy of rows, I need to use Excel format (can't use CSV). I'm wondering if IExcelDataReader will support this hierarchy of a row being contained inside of another row. I am not finding any documentation on this.
I don't see anything in IExcelDataReader that mentions Excel Row Groups. But there is an easier way that won't require you to use Excel sheets at all.
In Smartsheet, you could add another column, and add the formula =COUNT(ANCESTORS()) to each row. This will give you a numerical value you can work with in CSV format. Topmost rows will have a value of 0, children of topmost rows will have 1, and so on. In the logic that manipulates your CSV, you can then determine the hierarchy quite easily.

Remove hyperlink from all the excel cells in a xls (MS-Interop) document using c#

Does anyone know how to efficiently remove all the hyperlinks from cells in an excel document using c#? I am using MS-Interop to deal with excel documents.
Thank you!
https://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.range.clearhyperlinks.aspx
Calling the ClearHyperlinks() method on the specified range is equivalent to using the Clear Hyperlinks command from the Clear drop-down list in the Editing section of the Home tab. Only hyperlinks will be removed; all other cell content, such as text and formatting will be unaffected.

How do I set AutoFilter when building XML with StringBuilder in C# for Excel?

I'm not using any third-party libraries like EPPlus or the OpenXml spec. I'm not exporting HTML or a GridView for my datasource. I am not using VBA. I am reading data from a DataTable and building the string representation of the xml that represents the data and saving it as an .XLS file. The problem is that I can't seem to get <AutoFilter /> to work in any way that I've been able to find so far:
Added <autoFilter ref=\"A1:D33\"></autoFilter> just before the closing tag.
Added <AutoFilter ref=\"A1:D33\"></AutoFilter> just before the closing tag.
Added <autoFilter ref=\"A1:D1\"></autoFilter> just before the closing tag.
Added <AutoFilter ref=\"A1:D1\"></AutoFilter> just before the closing tag.
Added <AllowFilter /> to <WorkSheetOptions /> tag.
Added ref=\"A1:D33\" to the <Table /> tag.
Added ref=\"A1:D1\" to the <Table /> tag.
I'm not asking for someone to tell me to use some other tool to build this. I am completely comfortable using any number of methods to build Excel outputs, but that is not my requirement for this particular code.
If anyone has a completely working example set of XML that I can copy/pasta I would be ecstatic...
I'm not sure what you mean by building XML data and saving it to .XLS. As far as I know, that's not doable. Unless you're talking about the "old" version of the Office XML format (the "new" version is Open XML, but you mentioned you're not using that). You also didn't mention where you want the AutoFilter (because there are 2 places, one for the worksheet and one for tables).
So here are a couple of suggestions:
If it's for a table, put the autoFilter tag as the first child tag within the table tag.
If it's for a worksheet, the autoFilter tag should be after these child tags of worksheet (if present): sheetPr, dimension, sheetViews, sheetFormatPr, cols, sheetData, sheetCalcPr, sheetProtection, protectedRanges, scenarios (and then autoFilter). Those child tags are also the very first set of child tags of worksheet.

Exporting a ListView to Excel

I have a ListView that I need to export to an Excel spread sheet. There a bunch of documentation to export GridViews and to a lesser extent ListViews to Excel but not so much in terms of doing some customization before export.
Before exporting I need to prep the data, as a) only a subset of the columns need to be exported b) some of these columns are editable textbox controls.
Doing a simple export without preping the table means that the control gets exported as well which obviously looks really ugly.
At the moment I can iterate the controls and remove the formatting from both the Grid and ListViews thus solving b.
In the GridView and I can just set some the columns I want to hide using Visible = false; and then set back to true when I have finished.
The thing I can't figure is how to do this with the listview.
I am wondering what is the best way to do this as I am kind of stuck.
Thanks,
Michael
I actually think this is a dumb question. If I want to export the list view to excel then i'll export all columns removing the unnecessary formatting. Then users can do any customization of the columns in Excel.
To do any customization of the data prior to export then I should use the underlying data types.
The above approach (admittedly my own) is simply bad.

How do you programmatically break up one Excel document into several while still maintaining each cell's style and format?

m trying to break one large Excel spreadsheet into several. I've made good progress, but I'm running into some problems. Specifically, the values that get copied over don't retain their format (for instance, 40322 instead of 5/24/2010 and -101 instead of (101.00) ). I've tried using the style (see below) but that doesn't even get me the font, let alone the number format. Any help or a poke in the right direction would be appreciated.
There are 2 loops, one for row, one for column.
destinationSheet.Cells[i, j].Style = sourceSheet.Cells[i, j].Style;
Instead of looping for each cell, you can copy/paste the entire range of cells using the pastespecial method.
http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.namedrange.pastespecial(VS.80).aspx

Categories

Resources