Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
How to check whether excel values are formatted (bold/italic...)? C#

I want to open one excel file pragmatically. I want to show that values from excel in to grid. But if excel values are bold, values in grid should be bold.
How can i do this?

How can i read excel ? If i read excel in to data table, how can i check whether values are bold\italic ?


For example.
I have one excel file with two columns.Some of the values in that excel are bold.Some of them are italic. I want to add these values in excel in to a grid view. If value in the excel is bold value in grid should be bold. So i want to check whether the value in excel is bold\italic.
If i read excel in to datatable then show in gridview will not check the format of that value in excel.In grid view it will a plain text.
Posted
Updated 23-Nov-14 19:52pm
v3
Comments
ZurdoDev 21-Nov-14 11:11am    
If you read it as a DataTable you can't because that's just data and not formatting. You'll need to use the Excel Interop dll.
Am Gayathri 24-Nov-14 1:24am    
Can i do this if i use Excel interop dll ?
Maciej Los 23-Nov-14 15:58pm    
What have you done till now? Where are you stuck?
Am Gayathri 24-Nov-14 1:24am    
I have to start but thinking how can i read excel and how can i check whether values is bold?

1 solution

Hi Kavitha,

As Ryan said, you will have to use Interop to apply formatting.
And yes you can do this if you use Interop
Check out these examples:
http://stackoverflow.com/questions/7401996/microsoft-interop-excel-formatting-cells[^]
Formatting columns in Excel[^]

Regards,
Praneet
 
Share this answer
 
Comments
Am Gayathri 24-Nov-14 1:51am    
Hi Praneet,
Thanks for your replay.
I guess the example links you have given here is explains about how to format the excel. But my requirement is different. I want to check whether excel values are formatted.
For example.
I have one excel file with two columns.Some of the values in that excel are bold.Some of them are italic. I want to add these values in excel in to a grid view. If value in the excel is bold value in grid should be bold. So i want to check whether the value in excel is bold\italic.
If i read excel in to datatable then show in gridview will not check the format of that value in excel.In grid view it will a plain text.

Hope you understood requirement now.
[no name] 24-Nov-14 2:01am    
Oh I see. In that case read your excel file into an excel object. Look here:
http://www.codeproject.com/Tips/696864/Working-with-Excel-Using-Csharp

Then create a datatable with an aditional field to store the format. While converting this excel to a datatable, check for a format and insert italic or bold into the datatable column. And after bindinf this table to a grid, onrowdatabound you can apply your style for each row.
[no name] 24-Nov-14 2:02am    
I think someone else could also suggest the best way to to that. I thought it that way
Am Gayathri 24-Nov-14 3:01am    
R u experienced in SP2010 ?
[no name] 24-Nov-14 3:05am    
No Kavitha. I am not.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900