Click here to Skip to main content
15,881,813 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello!


Can excel be formated in c#? And if i can, how do i proced?

What I have tried:

Nothing, i need to understand first if it's possibile
Posted
Updated 14-Jan-19 20:42pm
Comments
Richard Deeming 18-Jan-19 11:53am    
NB: If you're writing a website, a Windows service, or anything else that runs in the background instead of in an interactive session, then you can't use Office Interop:

Considerations for server-side Automation of Office[^]
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

In this case, you would need to use an alternative library - for example:
* EPPlus[^];
* ClosedXML[^];
* The OpenXML SDK[^];

Google Microsoft Office Interop in C# or Excel Automation in C#
 
Share this answer
 
Quote:
Can excel be formated in c#?

Yes it can.
Quote:
And if i can, how do i proced?

If you can do it with Excel and mouse/keyboard, Excel can tell you how to convert to code.
- Open XL, get ready to do stuff.
- Start to record a macro
with xl2003, Menu > Tools > Macro > New Macro
with ribbon use Dev Ribbon
- Do your stuff
- Stop macro recording
- Open VBE (Visual Basic Editor)
- The code of macro is how your stuff translate to code.
Even if code need tuning, VBA is close to what you need for C#.
A little search on internet will give missing information.
 
Share this answer
 
Here is a simple example. There is a ton of information on MSDN around C# and the Interop libraries.

C#
Microsoft.Office.Tools.Excel.NamedRange myRange =
this.Controls.AddNamedRange(this.Range["A1", "A5"], "myRange");

myRange.NoteText("This is a Formatting test", missing, missing);
myRange.Value2 = "Text I want to Format";
myRange.Font.Name = "Arial";
myRange.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
myRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
 
Share this answer
 

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