旋转 Visio 形状文字

创建一个 Diagram

Aspose.Diagram for .NET 允许您从自己的应用程序中读取和创建 Microsoft Visio 图表,无需 Microsoft Office 自动化。创建新文档的第一步是创建一个 diagram。然后添加形状和连接器构建 diagram。使用默认构造函数Diagram类创建一个新的 diagram。

编程范例

// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Diagrams();
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Initialize a new Visio
Diagram diagram = new Diagram();
dataDir = dataDir + "CreateDiagram_out.vsdx";
// Save in the VSDX format
diagram.Save(dataDir, SaveFileFormat.VSDX);

这个例子的工作原理如下:

  1. 创建 Diagram 类的对象。
  2. 获取特定页面
  3. 得到特定的形状
  4. 获取Shape文字并旋转文字
  5. 调用 Diagram 类对象的 Save 方法,并传递完整的文件路径和 DiagramSaveOptions 对象。

旋转文字编程范例

下面的示例代码显示了如何旋转 Visio diagram 中的文本。

// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_ShapeText();
// Call the diagram constructor to load diagram from a VDX file
Diagram diagram = new Diagram(dataDir + "UpdateShapeText.vsd");
// Get page by name
Page page = diagram.Pages.GetPage("Flow 1");
// Find a particular shape and update its text
foreach (Aspose.Diagram.Shape shape in page.Shapes)
{
if (shape.NameU.ToLower() == "process" && shape.ID == 1)
{
shape.Text.Value.Clear();
shape.Text.Value.Add(new Txt("New Text"));
// Set orientation angle
double angleDeg = 90;
double angleRad = (Math.PI / 180) * angleDeg;
shape.TextXForm.TxtAngle.Value = angleRad;
}
}
// Save diagram
diagram.Save(dataDir + "UpdateShapeText_out.vdx", SaveFileFormat.VDX);