How to get the value of a merged cell? - c#

I am working on a project which has to make pdf report from couple of Excel files. The files should look like this: http://img194.imageshack.us/i/24766860.jpg/ and the pdf should look like this: http://img96.imageshack.us/i/u2ntitled.jpg/ where the location column must have the value of the merged cell in the excel file(B2:E2).
So the difficulty is how to read the merged cell and put its value in the location column.
If that info is not enough I can add the source code. If you want any other info ask I'll give it right away.

Merged cells in excel are read by their first cell address. You should be able to pick up merged cell B2:E2 as B2

Related

How to save OLEObject pdf file from excel

I have an excel file and one cell of every row contain embed pdf file object and remaining cells contain string values. Excel file looks like click here
I want to save this excel file data in sql database table, I can read the cell data of Date, Store, Category, Cost, Total, Method columns using oledb provider or using Workbook and Worksheet classes and save it in database table fine.
but coming to the Receipt column it showing null value when reading from either oledb or worksheet,
I want to save embedded object in local folder row wise and get filepath
Insert excel row data and for 'Receipt' column I need to save filepath
I will show this data in grid, for Receipt column I will set hyperlink and give filepath, so user can view the pdf that saved of that row.
How to implement using "Microsoft.Office.Interop.Excel" namespace and "OLEObject" class.
Any ideas please share it will helpful, I dont want to use third pary assembly references like GemBox, Aspose, etc.
Thanks,
Ajay

How to put value into span cell using aspose.cell?

I am using Aspose. Cell for .net to write some data into Excel. I have a quick question:
what are the best practices to get and write a value into the below cell?
this kind of cell may be across multiple columns/rows, does it belong to Rang or a special cell?
thanks
If it is merged cell, then you should use Cell object (you may use its PutValue method to insert data). Please note, in MS Excel sheet, when you merge a range of cells, the merged cell’s name will be top left cell,
so it will be accessed by that name. For example, when you merge "B1:F3" cells, it will become one big cell (B1). Now you got to access and insert data into B1 cell if you want to insert some data into that merged area range.
PS. I am working as Support developer/ Evangelist at Aspose.

How to not skip empty cell in Excel when creating .csv file

hope you guys can help!
I am trying to create .csv out of Excel which would have columns A - H filled with some data I want to read but data is optional. So some times the first column A can be empty. Now, when I save the .csv, unless I entered one space in the A column, Excel automatically trims A column, and the result is 7 cells to read A - G instead 8 cells A - H (with A column) being "empty". I would like to save client the trouble of needing to enter one space or -> ="" in the Excel formula to make first or last column "empty" but not trimmed in the resulting .csv.
Thank you!
There is no option in Excel to preserve empty columns, when exporting to .csv. But you could introduce a header text in the first row, so you will always have the columns filled atleast with the header text.
Plus it would make your data probably more readable, depending on what data this is.
Another possibility would be to implement a makro and embedd a button in your excel file:
see
how not to skip empty first cell when saving as .CSV?

C# - Find all matches in worksheet using Excel

enter image description here
I would like to find all "NC2" mathces in this worksheet (later the B column values).
I tried with range.find but I got back only one result.
How can I read out these cells? (Which contains NC2)
what I would do is do a data -> filter to get all the cells.
if it helps, conditional formatting would also help to visually find all the cells containing NC2.

How to Insert Values in Specific Excel Cells From DataGridView

Can you please help me to figure out how I can insert DataGridView values into a pre defined excel template (Into Specific Cells)?
I have a DataGridView on my windows Form which is getting the values from user input. Now I would like to enable users to export the DataGridView values into an excel file (A File like attached excel file).
As far as I know I have to create the headers and add them to the code programmatically but for the DataGridView part, honestly I have no idea how I can do that?
As you can see the Form (Box) is starting from B2 to K2 and end from B21 to K21 Now my question is how i can start importing values from B4 - k4 and so on?
Is there any way I can format the style of the cell (like Background color or font style and size) from C#? I mean generating a form like what is looking in attached Excel programmatically.
Thanks for your time in advance
Not sure if this is what you're looking for but ff you are using Office Interop, you can insert a 2-dimensional array into a range in Excel.
The following snippet might not be correct (no VS nearby and I haven't used excel automation for a long time) but you'll get the picture.
Excel.Range oRange = oSheet.Range("B2",Missing.Value);
oRange.Resize(myArray.GetLength(0),myArray.GetLength(1));
oRange.Value = myArray;

Categories