gpt4 book ai didi

c# - 使用 EPPlus 显示带有垂直文本的单元格

转载 作者:行者123 更新时间:2023-12-04 20:04:18 33 4
gpt4 key购买 nike

使用 EPPlus,如何更改单元格文本以显示为这样的垂直文本,

Sample

在 excel 中,您可以通过在设置单元格方向时单击此按钮来执行此操作,

Excel orientation

我正在尝试使用 .TextRotation但这并没有达到我想要的效果,将其设置为 180 度会给我这样的结果,

enter image description here
ws.Cells[row, 2].Style.TextRotation = 180; , .TextRotation只接受一个整数值,所以我想知道如何获得“文本”按钮的值,

最佳答案

它绝对是您发现的错误。有一种方法,但它很丑陋。您可以使用 StyleID当您将其更改为默认值以外的任何内容时由单元格创建:

[TestMethod]
public void Text_Rotate_Test()
{
//https://stackoverflow.com/questions/57603348/display-cell-with-vertical-text-using-epplus

var fileInfo = new FileInfo(@"c:\temp\Text_Rotate_Test.xlsx");
if (fileInfo.Exists)
fileInfo.Delete();

using (var pck = new ExcelPackage(fileInfo))
{
var workbook = pck.Workbook;
var worksheet = workbook.Worksheets.Add("Sheet1");
var cell = worksheet.Cells[1, 1];

cell.Value = "Test Text Value";

//Trigger epplus to create a new style specific for the cell.
//This needs to be done even thought it will be overridden in
//order to ref by index. But have to be careful not to step
//on other styles so make it as unique as it needs to be.
cell.Style.TextRotation = 180;

//Make sure the update the xml before looking up by index
workbook.Styles.UpdateXml();
workbook.Styles.CellXfs[cell.StyleID].TextRotation = 255;

pck.Save();
}
}

这给出了这个:

enter image description here

关于c# - 使用 EPPlus 显示带有垂直文本的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57603348/

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