将Excel仪表板导出到PowerPoint

时间:2018-10-15 13:16:46

标签: excel excel-vba powerpoint powerpoint-vba

我正在尝试基于Excel文件和用户输入创建PPT生成器。到目前为止,我设法创建了UserForm,用户可以在其中定义他想在演示文稿中查看的Excel报告(图表加表格)。为了定义选择哪个报告,我使用了全局变量。现在,当我尝试生成演示文稿时,出现错误:“运行时错误'-2147023170(800706b3)':自动化错误。远程过程调用失败。”调试显示第import os import pathlib from flask import Flask, render_template, request from werkzeug.utils import secure_filename app = Flask(__name__) app.config['SECRET_KEY'] = '^%huYtFd90;90jjj' app.config['UPLOADED_FILES'] = 'static/files' @app.route('/upload', methods=['GET', 'POST']) def upload(): if request.method == 'POST' and 'photos' in request.files: uploaded_files = request.files.getlist('photos') task_name = request.form.get('task_name') filename = [] pathlib.Path(app.config['UPLOADED_FILES'], task_name).mkdir(exist_ok=True) for file in uploaded_files: filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOADED_FILES'], task_name, filename)) return task_name return render_template('upload.html') if __name__ == "__main__": app.run(debug=True) 行 因为使用函数For来检查是否已选择报告(基于我的全局变量),所以我有多行这样的内容,如果是,则为每个报告重复代码。 下面是代码本身。我不确定自己在做什么错。

newPowerPoint.ActivePresentation.Slides.Add newPowerPoint.ActivePresentation.Slides.Count + 1, ppLayoutTitleOnly

我在这里没有想法。我不知道如何更正代码。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

我的建议是,当您从Excel vba以编程方式创建PowerPoint并使用ActiveSheet等时,不要“选择”对象;将对象直接设置到要使用的图纸上。就是说,虽然没有完全清理您的代码……这是可行的(仅针对CB1 ...,但其余应该相似):

代码已更新

/**
 * Returns HTTP headers for temporary content.
 * These headers prevent search engines from caching temporary content and asks them to revisit this page again.
 * Please ensure to also send a 503 HTTP Status code with these headers.
 */
protected function getHttpHeadersForTemporaryContent(): array
{
    return [
        'Retry-after' => '3600',
        'Pragma' => 'no-cache',
        'Cache-control' => 'no-cache',
        'Expire' => 0,
    ];
}

这是测试数据集的图片

screen1

这是输出PowerPoint的图片...

希望这会有所帮助。

screen2

相关问题