gpt4 book ai didi

c# - 文本与合并单元格中心的 EPPlus 垂直对齐不起作用

转载 作者:行者123 更新时间:2023-12-04 16:47:16 29 4
gpt4 key购买 nike

我试图将文本垂直对齐到中心,但它不起作用。文本出现在合并单元格的底部。这是不起作用的最小代码。

// get handle to the existing worksheet
ExcelWorksheet worksheet = xlPackage.Workbook.Worksheets.Add("mysheet");

//[row,col]
worksheet.Cells[1, 1].Value = "a1";
worksheet.Cells[2, 1].Value = "a1";
worksheet.Cells[3, 1].Value = "a1";
worksheet.Cells[4, 1].Value = "a1";
worksheet.Cells[5, 1].Value = "a1";
worksheet.Cells[6, 1].Value = "a1";

//comment out below six lines to make it work
worksheet.Cells[1, 2].Value = "11";
worksheet.Cells[2, 2].Value = "12";
worksheet.Cells[3, 2].Value = "13";
worksheet.Cells[4, 2].Value = "14";
worksheet.Cells[5, 2].Value = "15";
worksheet.Cells[6, 2].Value = "16";
//comment out above six lines to make it work

worksheet.Cells["A1:A6"].Merge = true;
worksheet.Cells["A1:A6"].Style.VerticalAlignment = ExcelVerticalAlignment.Center;

xlPackage.Save();

请帮忙。

在末尾添加这些行使其工作:

worksheet.Column(1).Style.VerticalAlignment = ExcelVerticalAlignment.Center;worksheet.Column(2).Style.VerticalAlignment = ExcelVerticalAlignment.Center;

这意味着我必须将所有列居中对齐才能居中对齐第一列。

最佳答案

试试这个...

using OfficeOpenXml.Style;
worksheet.Cells["A1:A6"].Style.VerticalAlignment =
ExcelVerticalAlignment.Center;

或者...worksheet.Cells["A1:A6"]. =OfficeOpenXml.Style.ExcelVerticalAlignment.Center;

关于c# - 文本与合并单元格中心的 EPPlus 垂直对齐不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38413998/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com