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");
    }
}
相关推荐
pcplayer20 小时前
非常好用的 Excel 读写控件
excel·delphi·office
weitingfu15 天前
Excel VBA 入门到精通(十):实战项目——自动化报表系统开发
ai·信息可视化·自动化·excel·vba·office·报表系统
humors22118 天前
微软工具包下载网址
windows·microsoft·微软·office·工具包·sysintervals
lys_82819 天前
【工具】pptx自动插入当前日期和自动页码
office·办公·自动页码·自动日期
simple_whu1 个月前
目录中不显示标题中间的软换行符Shift+Enter
word·office
Texous3 个月前
Java解析Excel图片
java·excel·wps·office·excel图片处理·excel图片解析·excel图片提取
初九之潜龙勿用3 个月前
C# 操作Word模拟解析HTML标记之背景色
开发语言·c#·word·.net·office
零零发聊技术3 个月前
Office各版本的简介、下载和注册
office
零零发聊技术3 个月前
Excel实现数字与列标之间的转换
excel·vba·office
初九之潜龙勿用3 个月前
C#实现导出Word图表通用方法之散点图
开发语言·c#·word·.net·office·图表