How set height row in excel with NPOI? - c#

How set height row in c# with NPOI?
To specify the width of the columns I'm using XSSFSheet.SetColumnWidth, but what does the command for the height of the cells look like?

try below approach
var row = sheet.CreateRow(0);
row.Height = 10 ;
//Or
sheet.GetRow(1).Height = 10;

The height of the row is the same:
XSSFSheet.GetRow(index).Heigh {get;set;}

In addition to #kumar answer, you can set it like this
row.HeightInPoints = 16.5F;

Related

How can I control table column width in Word documents using DocX?

I am trying to recreate a table like this:
I am using the DocX library to manipulate Word files, but I'm having trouble getting the widths right. Trying to set the widths of cells only seems to work when it's not set to the window autofit mode, and it only seems to resize when the specified width is greater than half of the table width, or rather, I can make a cell bigger than half the width but not smaller.
What would be the simplest way to reproduce the intended table?
I found the answer to this myself. In order to properly set the width, you have to loop through each cell in a column and set every width. This will not work with any autofit options selected.
Try this :
Table table = doc.AddTable(2, 2);
table.SetColumnWidth(0, 500);
//first is column index, the second is column width
Bit of an old post to tag to, but after having the same issue it would appear that none of the widths on either the cells or columns actually work, so as a dirty workaround, you can loop through each column and cell adding text to each of the cells, make the text white and finally use the autofit option to autofit to contents eg.
Table t2 = doc.AddTable(2, 8);
for (int i = 0; i < t2.RowCount; i ++)
{
for(int x = 0; x < t2.ColumnCount; x++)
{
t2.Rows[i].Cells[x].Paragraphs.First().Append("12").Color(Color.White);
}
}
t2.AutoFit = AutoFit.Contents;
doc.InsertTable(t2);
This is the way:
Table t = doc.AddTable(1, 5);
t.SetWidthsPercentage(new[] { 20f, 20f, 40f, 10f, 10f }, 500);
The float array sets width percentage for each of the columns, second parameter is the total width of the table.

Change width and height of column using ExcelPackage

I'm writing some code for my NopCommerce webshop, that needs to export an excel sheet.
I'm trying to edit the width of the columns, so the text will fit in.
I already tried the following code(for 26 columns):
//adjust excel column width
for (int i = 0; i < 26; i++)
{
worksheet.Column(i, 1).Width = 45;
}
The code executes and the Width of the columns is 45, so you could say it works.
But it gives me the following error at start up:
How can I get rid of this error?
Thanks in advance!
have you tried worksheet.Column(i).Width = 45; ?

setting cell width with epplus affects the whole column

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!
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();
Hi you can try like this
using (ExcelPackage pck = new ExcelPackage())
{
ExcelWorksheet ws = pck.Workbook.Worksheets.Add("1232");
ws.Cells["A1"].AutoFitColumns();
//ws.Cells[""].AutoFitColumns(20);//overloaded
//ws.Cells[""].AutoFitColumns(20,40);//overloaded min and max lengths
}

how can I change height value to cell or column of datagridveiw , by c# code?

how can I change height value to cell or column of datagridveiw , by c# code?
You can change height of row with DataGridViewRow.Height. If you mean only one cell then I can't imagine how it will looks.
added:
Hope this helps:
dataGridView1.RowTemplate.Height = 50;
foreach (DataGridViewRow r in dataGridView1.Rows)
r.Height = 50;

HowTo define the "Auto" Width of the WPF GridView Column in Code?

I want to define the "Auto" width of a GridView Column in the code. How can I do that?
var grid = (GridView)myListview.View;
grid.Columns.Add(new GridViewColumn
{
Header = "My Header",
DisplayMemberBinding = new Binding("MyBinding"),
Width = ??? // Auto
});
GridViewColumn's Width property is of type double, but according to the MSDN page you can set it to Double.NaN ("not a number") to tell it to auto-size.
If you do that, you have to ask for its ActualWidth if you want to know the width it has auto-sized to.
In case you're looking to do the same thing in code for the Width property of a Column of a normal Grid control, use GridLength.Auto.

Categories