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");
    }
}
相关推荐
明月看潮生16 天前
青少年编程与数学 01-012 通用应用软件简介 01 Microsoft Office办公软件
microsoft·青少年编程·office·应用软件
ONLYOFFICE22 天前
ONLYOFFICE协作空间API指南:使用JavaScript SDK为每个用户结构化协作房间
javascript·编辑器·onlyoffice·office·文档编辑与协作
Learn-Share_HY1 个月前
[Excel VBA]如何製作買三送一優惠條件的POS結帳介面?
excel·vba·office·自動化·自動化辦公
洛可可白1 个月前
Vue2实现Office文档(docx、xlsx、pdf)在线预览
javascript·vue.js·pdf·word·excel·office
課代表2 个月前
Office 中 VBE 的共同特点与区别
word·excel·vba·office·vbe
jiandongg2 个月前
【已解决】WORD域相关问题;错误 未找到引用源;复制域出错;交叉引用域到底是个啥
windows·microsoft·word·引用·参考文献·office·
蓝点lilac3 个月前
C# Office COM 加载项
com·office
Dymc4 个月前
【Visio使用教程】
office·visio
狂小虎4 个月前
亲测解决笔记本触摸板使用不了Touchpad not working
电脑·office
lisw054 个月前
office或者word排版中,复制/黏贴进来文字不会自动换行,如何处理?
word·office