Combining Multiple Excel Spreadsheet From SSRS In C# Console App - c#

I am trying to combine a directory of Excel Workbooks that have 1 worksheet each which I generated from SSRS into one workbook without losing its formats and Cell Styles and merged cells. I am trying use NPOI but I can't seem to fins anything that will keep my formatting (Each spreadsheet was generated from several sub reports into one report so the layout from SSRS is contains various merged regions). Any ideas on how I might accomplish this?

Related

Update Stylesheet of an existing Excel file using openXML

I am trying to copy an Excel workbook with 4 worksheets (tabs) where 1 worksheet is macro enabled with many formulas using the OpenXML SAX approach as I have lot of data for each sheet.
If I copy the file and and start writing into the worksheets, it starts writing from the 1st line and the headers are being deleted. So I tried copying just the macro-enabled sheet and add other sheets later and add styles to headers.
When I try doing it, the system give an error saying only one style sheet is allowed. Only one instance of the type is allowed for this parent.
How can I access the existing stylesheet and add more styling into it for other tabs?

Excel formula calculation using OpenXML

I have scenario where I have to prepare two batch of excel files. I have two templates. I am automating a process. The 1st Excel file has formulas in it. I populate data using C# winform and OpenXML library in the first excel file. I want to have the formulas calculate results and then grab them to populate the 2nd excel file. I have tried various methods but was unsuccessful. I did use the following code hoping it will make the excel file calculate the formulas in it.
SpreadSheetDocument.WorkbookPart.Workbook.CalculationProperties.ForceFullCalculation = true;
SpreadSheetDocument.WorkbookPart.Workbook.CalculationProperties.FullCalculationOnLoad = true;
So basically the process should be
Make copy of the 1st excel file and populate it with data [This part is working]
Some how make the 1st excel file data calculate the formulas [This is the step I have problem with]
Copy the formula results values to the 2nd excel file [This part is working but as formula is not calculated the values are not being copied over]
I am reluctant to use excel interlop library as closing the excel does not work as well.

Excel Automation: read a csv file and update an Excel file

I have an automated test which produces a csv with two columns of data.
I have an excel file which I use to gather the results of all the runs in a worksheet.
I want to fully automate the process of updating the Excel file after each test run.
This is probably what I want to do:
1. Read the two columns from the CSV file
2. Paste the two columns in a worksheet in the excel file, in the first
empty column to the right of the existing block of columns.
3. Save the Excel file
EDIT:
Now i understand that i can do steps 1-3 using a macro.
All that is left for me to figure out is how to launch the macro.
You can read the csv and write to the Excel sheet with a single data provider, the OleDb provider. Here is an article on how to write to Excel, and here is one on how to read csv.
Once you write the macro, it should be in the macro list in Excel for that Excel document. You can bind the macro to a keystroke (like Alt-i, Alt-whatever) so that it runs when your press that key combination.
I've done this on a couple of similar projects where I need to import CSV files from other sources and put the data into an Excel sheet (or sheets)

Excel interop writes excel files that contain "empty" cells

I have a c# tool that creates excel worksheets, which will be later read in again by another tool. This is done by using excel interop.
when reading the generated excel file, an exception stating: OleDbException: Too many fields defined.
it means that the file cannot be read in because there are too amny columns, but there should not be, as the real content only takes about 90 columns. As a workaround i deleted all the other columns manually in excel, and tried again to read it in.
this works as expected, so that means that the generated excel does contain nonempty cells (which are shown as empty cells in excel...)
is there a way to tell the inerop not to create empty cells, or is there another reason i should check?
Many thanks
Tom
PS: I am experiencing this problem with the 2003 interop libraries, while i've got Office 2007 installed.
I've Found the solution:
The tool was copying ranges from one sheet to another.
The source range was properly defined:
GetRange(fromWorkbookName, fromSheetName, A1, V20);
The destination cell hoever was adressed by:
GetRange(toWorkbookName, toSheetName, A1).EntireRow;
In 2003 interop, this seemed no Problem.
When doing this towards an xslx file i Office 2010, some "Empty" fields containing "#N/A" were created.
Nasty nasty...
anyhow the tool was not doing the copy/paste correctly (even excel itself warns you when you copy a range manually to an entire line). After correcting this it seems to work....

Dataset to excel

I'm developing an application that as to export a dataset to excel, this dataset have 3 tables and the relation between them, I would like to export this to a single excel sheet where for each parent table there is a '+' sign that when expanded shows the child values related to it. To export a single table to excel I know how to do it, but to create this type of relation I have no idea how to do it, do I have to create a macro on the excel file?
I use a DevExpress Reports or a ActiveReports for this. I create a normal report and next i save it in xls, and Done. Its very complicated to this using us code. Its more easy to use a third-party components
There's a free tool: https://closedxml.codeplex.com/ to create XLSX outputs from code.

Categories