aardio 文档

aardio 范例: PPTX 文本读取 · 不需要 Office

import win.ui;
import fsys.dlg;
/*DSG{{*/
var winform = win.form(text="PPTX 文本读取 · 不需要 Office";right=799;bottom=539)
winform.add(
button={cls="button";text="选择演示文稿…";left=16;top=16;right=180;bottom=48;anchors={left=1;top=1};z=1};
status={cls="static";text="只读提取文本、基本表格和备注,不渲染页面";left=196;top=22;right=781;bottom=46;anchors={left=1;top=1;right=1};z=2};
output={cls="edit";left=16;top=64;right=782;bottom=522;edge=1;multiline=1;readonly=1;vscroll=1;hscroll=1;anchors={left=1;top=1;right=1;bottom=1};z=3}
)
/*}}*/

var readFile = function(path){
    winform.button.disabled = true;
    winform.status.text = "正在读取…";
    // 在工作线程解析,等待时界面仍处理消息。结果是可跨线程传递的纯数据。
    var data,err = thread.invokeAndWait(function(path){
        import fsys.openXml.pptx;
        return fsys.openXml.pptx.read(path);
    },io.fullpath(path));
    if(data){
        var lines = [];
        for i,page in data.pages {
            table.push(lines,"── 第 " + i + " 页 ──");
            table.push(lines,page.text);
            if(page.notesPart){ table.push(lines,"[备注]"); table.push(lines,page.notesText); }
            table.push(lines,"");
        }
        for i,item in data.warnings { table.push(lines,"[提示] " + item.message + ":" + item.partName); }
        winform.output.text = string.crlf(string.join(lines,'\r\n'),'\r\n');
        winform.status.text = "已读取 " + data.slideCount + " 页,含备注 " + data.noteCount + " 页;源文件未修改";
    }
    else{
        winform.output.text = err;
        winform.status.text = "读取失败";
    }
    winform.button.disabled = false;
    return data,err;
}

winform.button.oncommand = function(){
    var path = fsys.dlg.open("演示文稿|*.pptx;*.pptm;*.ppsx;*.ppsm;*.potx;*.potm|","选择演示文稿",,winform);
    if(path) readFile(path);
}

winform.show();
win.loopMessage();

Markdown 格式