在 VSTO 和 Aspose.Cells 中旋转 Cell 文本
Contents
[
Hide
]
要旋转工作表单元格中的文本,请执行以下步骤:
- 创建工作簿并获取工作表。
- 添加示例文本。
- 格式化文本:旋转,添加背景颜色。
- 保存文件。 下面的代码示例展示了如何首先在 VSTO 中使用 C# 执行这些步骤,然后在 Aspose.Cells 中再次使用 C#。
VSTO
//intiate Application object
Excel.Application ExcelApp = Application;
//Add a Workbook.
Excel.Workbook objBook = ExcelApp.Workbooks.Add(System.Reflection.Missing.Value);
//Get the First sheet.
Excel.Worksheet objSheet = (Excel.Worksheet)objBook.Sheets["Sheet1"];
//Put some text into cell B2.
objSheet.Cells[2, 2]= "Aspose Heading";
//Define a range object(B2).
Excel.Range _range;
_range = objSheet.get_Range("B2", "B2");
//Specify the angle of rotation of the text.
_range.Orientation = 45;
//Set the background color.
_range.Interior.Color = System.Drawing.ColorTranslator.ToWin32(Color.FromArgb(0, 51, 105));
//Set the font color of cell text
_range.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);
//Save the excel file.
objBook.SaveCopyAs("VSTO_RotateText_test.xlsx");
//Quit the Application.
ExcelApp.Quit();
Aspose.Cells
// Instantiate a new Workbook.
Workbook objworkbook = new Workbook();
// Get the First sheet.
Worksheet objworksheet = objworkbook.Worksheets[0];
// Get Cells.
Cells objcells = objworksheet.Cells;// Get a particular Cell.
Cell objcell = objcells["B2"];// Put some text value.
objcell.PutValue("Aspose Heading");
// Get associated style object of the cell.
Style objstyle = objcell.GetStyle();
// Specify the angle of rotation of the text.
objstyle.RotationAngle = 45;
// Set the custom fill color of the cells.
objstyle.ForegroundColor = Color.FromArgb(0, 51, 105);
// Set the background pattern for fillment color.
objstyle.Pattern = BackgroundType.Solid;
// Set the font color of cell text
objstyle.Font.Color = Color.White;
// Assign the updated style object back to the cell
objcell.SetStyle(objstyle);
// Save the work book
objworkbook.Save("RotateText_test.xlsx");
下载示例代码
- Github
- [Sourceforge](https://sourceforge.net/projects/asposevsto/files/Aspose.Cells%20Vs%20VSTO%20Excel/Rotating%20Cell%20Text%20(Aspose.Cells).zip/下载)
- [比特桶](https://bitbucket.org/asposemarketplace/aspose-for-vsto/downloads/Rotating%20Cell%20Text%20(Aspose.Cells)。压缩)