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");
    }
}
相关推荐
不坑老师2 天前
怎么在PPT里面插入网页?
microsoft·powerpoint·wps·office
spencer_tseng8 天前
Custom Animations for PPT (PowerPoint)
powerpoint·ppt·office
Shi_haoliu19 天前
Vue2 + Office Add-in关于用vue项目于加载项控制excel单元格内容(Demo版)
前端·javascript·vue.js·node.js·html·excel·office
恶猫22 天前
Polaris Officev9.9.12全功能解锁版
pdf·word·excel·ppt·office·办公·打工
爱考证的小刘1 个月前
微软MOS认证海外考生如何参加?
微软·office·微软mos认证·mos认证考试·mos·微软mos国际认证·mos考试语言
玩泥巴的1 个月前
.NET操作Word实现智能文档处理 - 内容查找替换与书签操作
word·.net·二次开发·office·com互操作
玩泥巴的1 个月前
.NET操作Word/WPS打造专业文档 - 页面设置与打印控制完全指南
word·二次开发·office·com互操作
玩泥巴的2 个月前
.NET驾驭Word之力:理解Word对象模型核心 (Application, Document, Range)
word·二次开发·office·com互操作
ChinaLzw2 个月前
Python 操作Office的PPT、Word、Excel,同时兼容WPS
python·wps·office
ONLYOFFICE2 个月前
如何在ONLYOFFICE中使用OCR工具:轻松识别图片和PDF中的文字
编辑器·ocr·office