Click here to Skip to main content
15,885,195 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Below is the code am using to create excel from datatable using openxml.

XLWorkbook workbook = new XLWorkbook();

workbook.Worksheets.Add(datatable, "excel");
workbook.SaveAs(pathtosave);

Its working perfect but all the cells are aligned left.
I want to align cells center, how to do that here?
Posted
Updated 30-Oct-14 4:36am
v2
Comments
Am Gayathri 30-Oct-14 10:36am    
Any solution ?
ZurdoDev 30-Oct-14 11:43am    
1. Slow down. This is a volunteer site.
2. Just record a macro in Excel doing what you want and you'll see the code you need.
Robert Welliever 30-Oct-14 23:18pm    
A macro would be a terrible solution. The biggest reason is that they are typically disabled when downloading from the web as they are a security violation.
ZurdoDev 31-Oct-14 7:42am    
Please re-read my suggestion.

Record a macro so you can see what the code should be. I did not suggest to use a macro but you can teach yourself so much coding by recording the macros and then looking at the code.
Philippe Mori 22-Apr-15 12:36pm    
Create manually the file you want and inspect it. Generate and study code created by tools in the SDK. If I remember well, you can even compare Excel files with tools in the SDK so it would be very easy to do.

1 solution

 
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