Read excel cell styling and formatting in C# - c#

I have an excel file located on SharePoint. I am reading the excel file in C# using OpenXML. While reading the data, I also need the information of any styles that are been added to the cells.
If there is any cell that has been added a background color to, How can I read it in C# ?

Have a look at this you will find some references about foreground color and background color of cell
https://social.msdn.microsoft.com/Forums/vstudio/en-US/c46f8610-0394-4eb9-a0f4-3d9a569817f0/other-properties-of-cell?forum=oxmlsdk

I don't know how you can do that with OpenXML, in the past i have always used Microsoft.Office.Interop.Excel. It's a nuget package that allow you to manipulate your excel style.
I hope it can help you!

Related

Is there any way to programaticallly save Excel cell to local files that could be load just like "copy and paste" with VSTO?

I've been working with Excel VSTO Add-in these days, and what I need is to load some templates from the database, and fill them in the Excel cells.
The thing is I can only store the data in plain text, the style and format would be missing if I try to copy and paste a target cell and store it somewhere in the notepads (or other editors).
Is there any way to save the cell data with styles to some binary local file (or others), and when I need it sometime, I could load and fill it to a targeted cell, like I have just copied it from some cells else.
Thanks!
PS: the text might have different styles so the storage of cell's formats might not work,
I've attached an example here:
I finally solved it with
Range.Value[XlRangeValueDataType.xlRangeValueXMLSpreadsheet]
It stores the cell as XML, with all the styles I need.

How to work with .xls file in C# application

In a C# console application I have a PointF[] array. I need to draw those points in an .xls chart file, but I need guidance how to do this?
Have a look at Open XML SDK 2.0 for Microsoft Office
I've used it before to do something like you're describing.
I started off creating an .xls file in Excel that had the correct chart which read values from a specific range of cells and so on. Then using the SDK I added/changed the values of those cells and saved a new version of the file. So basically I used the file created in Excel as a template that I could change whenever without changing the code (as long as the values are written to the same range of cells).
You could also put the value cells in a separate worksheet so that the user does not see them when opening the file...

asp.net excel plugin

What is the easiest way to save content to excel from .net pages?
I know there are a few packages on NUget but which is the easiest/best to work with?
I only need simple text so I know I can do .csv no problem but I need extra control over formatting such as make the text bold, italic, underlined, change cell colour which I do not believe it is possible to do via CSV.
Try EPPlus open source .net library that reads and writes Excel 2007/2010 files using the Open Office Xml format (xlsx).
NPOI is good for adding formatting. Open source
http://npoi.codeplex.com/

How to maintain formatting of cells when copying cells from Excel to Word

Currently I'm using OleDB to connect with Excel Spreadsheet and getting data in a DataTable, doing some modifications on data and then copying the data to Word.
In doing so I'm losing the formatting of the cell, like if any part of text was colored or if the background color was grayed or if it's bold.
I'm using Interop library to communicate with word and OLEDB with Excel.
If this solution is not good enough for what I need to achieve , can you suggest alternative solutions? (Macros?)
I tried using Interop.Excel.Styles but I can't figure out how to relate it with the cell being currently used.
We copy the range of the table in the spreadsheet and the directly paste in the word document which preserves formatting.
wordDoc.Tables.Add(b.Range,newsheet.UsedRange.Rows.Count,newsheet.UsedRange.Columns.Count);
Microsoft.Office.Interop.Word.Table table = b.Range.Tables[1];
newsheet.UsedRange.Copy();
table.Range.Select();
wordApp.Selection.Paste();
wordDoc is Word.Document and wordApp is word.Application. Hope this helps
Yeah, that's gonna happen. OleDB moves data, not formatting information. If you want the formatting, you're going to have to copy/paste from Excel to Word. If you need to automate the process, VBA is the easiest way to control Excel and Word from the outside.

Manipulating Excel Data using Visual C#

I need to set/insert hyperlinks for a range of values in an Excel sheet from my program written in Visual C#.
I am using "Microsoft.Office.Interop.Excel" and no third party Excel tools.
I have URLs in string format with me in the program which need to show up as Hyperlinks in the Excel workbook.
Any ideas on how this can be implemented? I did not see any familiar feature in Excel.Range which I could use. Any suggestions would be appreciated!
Thanks,
Ivar
Have you tried Hyperlinks.Add?
You can add a hyperlink to a range of cells (after setting the text content).

Categories