Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting cell width with epplus affects the whole column

Tags:

c#

asp.net

epplus

I'm having a bit of trouble on solving this. Is there a way to set the width of a specific cell from a worksheet using epplus? Because when i use, for example:

ws.Column(1).Width = 40;

the whole column gets affected.

Thanks in advance!

like image 591
Joao Victor Avatar asked Nov 07 '12 12:11

Joao Victor


People also ask

How do I adjust a column's width in Excel for a different table in the same sheet?

To change the width of columns to fit the contents, select the column or columns that you want to change, and then double-click the boundary to the right of a selected column heading. To change the width of all columns on the worksheet, click the Select All button, and then drag the boundary of any column heading.

How to adjust column width in Excel for printing?

Method 2: Manually resize the columnDrag the boundary on the right side of the column heading until the column is the width you want. Format menu and click Width. Type a smaller number and click OK. On the File menu, click Print Preview to preview the page.

Which two actions increase the size of the column width in Excel?

Click and drag the column to the right to increase column width or to the left to decrease column width.


1 Answers

As I know, there is no way to change the width of a specific cell. All cells in one column have same width. You can change the width of a cell by merging it with its neighbour. I have an example:

sheet.Cells["A1"].Value = "This is a cell";
sheet.Cells["A1:A2"].Merge = true;

Then you can set width by using

sheet.Column(1).Width = 40;

or

sheet.Cells["A1:A2"].AutoFitColumns();
like image 183
Han Avatar answered Oct 27 '22 00:10

Han