How to Dynamically Fetch excel Cell Range in Interop Excel using c# - c#

I am stuck in a situation where i have a dynamic pivot table that returns columns based on date range the user has selected
for eg : if user selects "Oct-2020" and "Feb-2021", following columns will be returned from datatable
Name
Oct-2020
Nov-2020
Dec-2020
Jan-2021
Feb-2021
Total
if user selects "Jan-2021" and "Feb-2021", following columns will be returned from datatable
Name
Jan-2021
Feb-2021
Total
i have custom tables as shown above, so i have used interop excel to export the resultset into excel sheet, i need to color column names based on column count. i have hardcoded range values, since, i am not able to get range dynamically
how do i fetch excel range dynamically based on column count and color its background
please help me

Related

Crystal reports, how to set specific rows in a given report format

I need to have a report as follows.
My issue is how to set the specific rows as the given format. I need to show the "All Contributions", "Participnt Contribution" and "Comparison" rows then a gray line and the other parameter rows.
I tried with grouping, but unable to have the gray line before the parameter rows.
All the data rows are coming from one data source. a C# data set.
Thanks in advance

Getting Excel Data Range from Sharepoint

I am trying to retrieve the data from Excel Sheet on Sharepoint by C# Code.
I can get the value for 1 cell in the excel. But I want the range of values(the whole column). How can i get that ?
Suppose on browser, I type :
http://test.net/excel/_vti_bin/ExcelRest.aspx/docs/MyExcelFile.xlsm/Model/Ranges('Sheet2!D4')?$format=HTML
I get the cell value. But Now I want to get the every value for Column D, how can I get it ?

How to add a table row to a word document using syncfusion in C#

I am very new to syncfusion and I am kind of stuck with this problem. I can easily populate a table if all of the rows and cells are created but I run into 'IndexOutofBounds' error once my data exceeds the number of rows in my template table. How can I add a row to a growing template table using Syncfusion in C#? I also would like to know how to handle the possiblity of the table growing to more than one page.
Adding a row is an easy task. After adding the row the cell paragraphs have to be added and formatted. That was the error I was running into.
IWTable table = new IWTable();
table.AddRow(True);
table.Rows[0].Cells[0].AddParagraph().AddText("sample text");
If you know the exact number of rows and columns, then you can utilize the below code to define rows and columns for a table.
IWTable table = document.LastSection.AddTable();
table.ResetCells(10, 4);
If you are not sure about the number of rows then you can use the below code to add a row dynamically.
table.AddRow();

How to read excel dynamically data and get combobox values

I have to dynamically read about 2000 files in Excel xlsx format, to import data to database using csharp. It´s not tabular data, no head columns at all, the data has to be read dynamically, because the positions of the cells change according to the product data, we have labels cells to find the data. My biggest problem is I can not read the value of combo boxes cause positions, name and quantity of cells/combos will change depending the product, but the labels will remain the same. I tried to export to every single format type but it doesn´t works, the combo selected value after specific cell label dissapears.
Any possible solution?
Ex. of my spreadsheet:
row A1: label|value|null value|label|value|merge cells label|value
row A2: label|producttypecombovalue
row A3: label|producttypecombovalue
row A4: label|producttypecombovalue...
row AX..: label|value|label|value|merge cells label|value
If the combo boxes are all positioned over the cell to the right of the label then you can filter all of the combos on the sheet by looking at their location (ie. their TopLeftCell property, or Top and Left properties) and using the one which most closely matches the expected position of the one you're looking for.
In VBA (using Forms combos, which from your screenshot are what you're dealing with) -
Sub tester()
Dim o
For Each o In ActiveSheet.OLEObjects
Debug.Print o.Name, o.Top, o.Left, o.TopLeftCell.Address(), _
TypeName(o.Object)
Next o
End Sub

I am displaying the contents of an Excel file in a Gridview. How do I handle merged cells?

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.

Categories

Resources