ワークシート内の形状でテキストを回転させる
Contents
[
Hide
]
考えられる使用シナリオ
Microsoft Excel を使用して、任意の図形内にテキストを追加できます。非常に古い Microsoft Excel 2003 を使用して図形を追加すると、テキストは図形と共に回転しません。ただし、Microsoft Excel の新しいバージョン (2007、2010、2013、2016 など) を使用して形状を追加すると、テキストは形状と共に回転します。テキストをシェイプに合わせて回転させるかどうかを制御できます。ShapeTextAlignment.RotateTextWithShape財産。そのデフォルト値は真実これは、テキストが形状とともに回転することを意味しますが、次のように設定した場合間違いの場合、テキストは形状とともに回転しません。
ワークシート内の形状でテキストを回転させる
次のサンプル コードは、サンプル Excel ファイル三角形の形をしており、そのテキストは形に合わせて回転します。 Microsoft Excel でサンプルの Excel ファイルを開いて三角形を回転させると、テキストも一緒に回転します。次に、コードはShapeTextAlignment.RotateTextWithShapeプロパティとして間違いそしてそれをとして保存します出力エクセルファイル.出力された Excel ファイルを Microsoft Excel で開き、三角形を回転させても、テキストは回転しません。サンプルの Excel ファイルに対するコードの効果を示す次のスクリーンショットを参照してください。
サンプルコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
//Load sample Excel file. | |
Workbook wb = new Workbook(sourceDir + "sampleRotateTextWithShapeInsideWorksheet.xlsx"); | |
//Access first worksheet. | |
Worksheet ws = wb.Worksheets[0]; | |
//Access cell B4 and add message inside it. | |
Cell b4 = ws.Cells["B4"]; | |
b4.PutValue("Text is not rotating with shape because RotateTextWithShape is false."); | |
//Access first shape. | |
Shape sh = ws.Shapes[0]; | |
//Access shape text alignment. | |
Aspose.Cells.Drawing.Texts.ShapeTextAlignment shapeTextAlignment = sh.TextBody.TextAlignment; | |
//Do not rotate text with shape by setting RotateTextWithShape as false. | |
shapeTextAlignment.RotateTextWithShape = false; | |
//Save the output Excel file. | |
wb.Save(outputDir + "outputRotateTextWithShapeInsideWorksheet.xlsx"); |