word中的内容旋转90度

在vsto、Aspose.Words 中,默认没有直接的 API 可以让表格整体旋转 90 度。然而,我们可以通过一些方式来实现类似的效果,具体思路如下:

将表格插入到一个形状(Shape)或文本框中,然后旋转该形状。

将表格内容旋转,这通过设置文本方向为垂直来模拟旋转效果。

java 复制代码
using Aspose.Words;
using Aspose.Words.Tables;
using Aspose.Words.Drawing;

class Program
{
    static void Main()
    {
        // 创建文档和 DocumentBuilder
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);

        // 创建 Shape(文本框)
        Shape shape = new Shape(doc, ShapeType.TextBox);
        shape.Width = 200;  // 设置文本框的宽度
        shape.Height = 400; // 设置文本框的高度
        shape.WrapType = WrapType.None;
        
        // 旋转 Shape 90 度
        shape.Rotation = 90;

        // 将 Shape 添加到文档中
        builder.InsertNode(shape);

        // 创建一个新的 DocumentBuilder 用于 Shape 内部
        DocumentBuilder shapeBuilder = new DocumentBuilder(doc);
        shapeBuilder.MoveTo(shape.FirstParagraph);

        // 在 Shape 内部添加一个表格
        Table table = shapeBuilder.StartTable();
        shapeBuilder.InsertCell();
        shapeBuilder.Write("Cell 1");
        shapeBuilder.InsertCell();
        shapeBuilder.Write("Cell 2");
        shapeBuilder.EndRow();
        shapeBuilder.InsertCell();
        shapeBuilder.Write("Cell 3");
        shapeBuilder.InsertCell();
        shapeBuilder.Write("Cell 4");
        shapeBuilder.EndTable();

        // 保存文档
        doc.Save("RotatedTable.docx");
    }
}
相关推荐
私人珍藏库6 天前
[Windows] Office Tool Plus V10.29.50.0
windows·工具·office·辅助
不坑老师9 天前
在Word、PPT中一键制作汉字笔顺分解步骤效果,自定义格子颜色、多种效果~
microsoft·word·powerpoint·wps·office
唆了蜜.9 天前
Office 2024 微软官方正式版镜像下载链接
microsoft·office
CodeCraft Studio16 天前
纯前端文档编辑组件——Spire.WordJS全新发布
前端·javascript·word·office·spire.wordjs·web文档编辑·在线文档编辑器
小云小白17 天前
vue3 前端文件预览实现
ofd·office·文件预览
初九之潜龙勿用24 天前
C# 操作Word模拟解析HTML标记输出带格式的文本
开发语言·c#·word·office
裤裤兔25 天前
利用VBA批处理word 文档,使用宏对docx文件内容进行批量替换
c#·word·.net··vba·office·宏操作
玩泥巴的1 个月前
.NET驾驭Excel之力:工作簿与工作表操作基础
c#·excel·二次开发·office·com互操作
Humbunklung1 个月前
Word技巧:制作可勾选的复选框并自定义选中符号
word·office
try_trying_try1 个月前
excel下拉选项设置
office