使用 EPPlus 显示带有垂直文本的单元格
Display cell with vertical text using EPPlus
使用 EPPlus,我如何更改单元格文本以显示为像这样的垂直文本,
在 excel 中,您可以在设置单元格方向时单击此按钮来完成此操作,
我正在尝试使用 .TextRotation
但这并没有达到我想要的效果,将它设置为 180 度会给我这样的效果,
ws.Cells[row, 2].Style.TextRotation = 180;
、.TextRotation
只接受整数值,所以我想知道如何获得 "Text" 按钮值,
这绝对是您发现的错误。有一种方法,但它很丑陋。当您将其更改为默认值以外的任何内容时,您可以使用单元格创建的 StyleID
:
[TestMethod]
public void Text_Rotate_Test()
{
//
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();
}
}
这给出了这个:
使用 EPPlus,我如何更改单元格文本以显示为像这样的垂直文本,
在 excel 中,您可以在设置单元格方向时单击此按钮来完成此操作,
我正在尝试使用 .TextRotation
但这并没有达到我想要的效果,将它设置为 180 度会给我这样的效果,
ws.Cells[row, 2].Style.TextRotation = 180;
、.TextRotation
只接受整数值,所以我想知道如何获得 "Text" 按钮值,
这绝对是您发现的错误。有一种方法,但它很丑陋。当您将其更改为默认值以外的任何内容时,您可以使用单元格创建的 StyleID
:
[TestMethod]
public void Text_Rotate_Test()
{
//
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();
}
}
这给出了这个: