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.
Related
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.
I've had a Google but I find no answer. You know how say in MS Word, when you insert a table, you can merge the columns of one single row to create a column-less row? Or have say a main header and then more columns inside it? Like so:
Merged Row:
|Column 1|Column 2|Column 3|
|Value|Value|Value|
|Merged Row|
|Value|Value|Value|
God the text formatting is awful on this web-site...and the Header Column example:
|Main Header||Another Main Header|
|Column 1|Column2||Column1|Column2|
I'm trying to achieve this in a written DataTable in C# which is being populated by an array. But I'm interested in changing its structure as one of the above, whichever is possible/easier.
So I've created my DataTable and added normal columns and rows etc. But I'd like to create either a merged row or a main header to display. Instead of having a repeated value in a single column for the values I am getting.
Can someone please provide a quick example on how I could achieve either one of those? Because repeated value will just look ugly.
Cheers.
You're talking about displaying data in a particular way but a
DataTable has nothing to do with display. It is for storage and that's
that. How you display the data is up to you. The same data can be
displayed in innumerable different ways. In a WinForms app, one of the
most common ways to display the contents of a DataTable is with a
DataGridView. You can choose which columns to display and merge cells
in that grid if desired. In short, you're looking in the wrong place
to do what you want to do. It is a presentation issue, not a data
issue. –
jmcilhinney
I want to read and display an excel file in a web page. I am using Microsoft.Office.Interop.Excel in .aspx.cs and GridView in .aspx. I am just reading it into a DataTable and binding it to GridView.
The problem with this is, I can't handle merged cells. For example, if two columns are merged in Excel, while displaying, it will show two columns with the value in first cell and second cell will be empty. I just want to retrieve the sheet as it is. Is there any way to achieve this?
Microsoft.Office.Interop.Excel is designed to provide programmatic access to excel files. It will do some formatting work (see Text property) but most of the difficulty of rendering is left to the consumer (your program).
MergeCells will return True if you have a merged cell and MergeArea will return a Range containing the merged cells. You can then use the RowSpan and ColumnSpan fields of the GridView's cells to duplicate the functionality.
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.
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