有没有办法读取ppt数据并存储在SQL表中 [英] Is any way to read ppt data and store in SQL table

查看:94
本文介绍了有没有办法读取ppt数据并存储在SQL表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我移动我的代码服务器2012时,我将收到以下错误。



PPTReadingConsoleApplication中出现未处理的System.Runtime.InteropServices.COMException类型异常.exe





检索具有CLSID {91493441-5A91-11CF-8700-00AA0060263B}的组件的COM类工厂失败,原因是以下错误:80040154





在我的本地系统中,ms -office在那里工作正常。但在服务器没有办公室。如何在服务器中读取ppt数据。



我尝试过:



使用System;

使用System.Collections.Generic;

使用System.Linq;

使用System.Text;

使用Microsoft.Office.Core;

使用PowerPoint = Microsoft.Office.Interop.PowerPoint;



名称空间readPPT

{

class program

{

static void Main(string [] args)

{

Microsoft.Office.Interop.PowerPoint.Application PowerPoint_App = new Microsoft.Office.Interop.PowerPoint.Application();

Microsoft.Office.Interop.PowerPoint。演示文稿multi_presentations = PowerPoint_App.Presentations;

Microsoft.Office.Interop.PowerPoint.Presentation presentation = multi_presentations.Open(@C:\ppt\RevisedKaizenTemplate.Rev1.pptx);

string presentation_text =;

for(int i = 0;我< presentation.Slides.Count; i ++)

{

foreach(展示中的var项目。滑动[i + 1] .Shapes)

{

var shape =(PowerPoint.Shape)item;

if(shape.HasTextFrame == MsoTriState.msoTrue)

{

if( shape.TextFrame.HasText == MsoTriState.msoTrue)

{

var textRange = shape.TextFrame.TextRange;

var text = textRange。文字;

presentation_text + = text +;

}

}

}

}

PowerPoint_App.Quit();

Console.WriteLine(presentation_text);

Console.ReadLine();

}

}

}

when i moved my code server 2012 i will get the following error.

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in PPTReadingConsoleApplication.exe


Retrieving the COM class factory for component with CLSID {91493441-5A91-11CF-8700-00AA0060263B} failed due to the following error: 80040154


In my local system ms -office is there and working fine. but in server no ms office. how to read ppt data in server.

What I have tried:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Core;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;

namespace readPPT
{
class Program
{
static void Main(string[] args)
{
Microsoft.Office.Interop.PowerPoint.Application PowerPoint_App = new Microsoft.Office.Interop.PowerPoint.Application();
Microsoft.Office.Interop.PowerPoint.Presentations multi_presentations = PowerPoint_App.Presentations;
Microsoft.Office.Interop.PowerPoint.Presentation presentation = multi_presentations.Open(@"C:\ppt\RevisedKaizenTemplate.Rev1.pptx");
string presentation_text = "";
for (int i = 0; i < presentation.Slides.Count; i++)
{
foreach (var item in presentation.Slides[i + 1].Shapes)
{
var shape = (PowerPoint.Shape)item;
if (shape.HasTextFrame == MsoTriState.msoTrue)
{
if (shape.TextFrame.HasText == MsoTriState.msoTrue)
{
var textRange = shape.TextFrame.TextRange;
var text = textRange.Text;
presentation_text += text + " ";
}
}
}
}
PowerPoint_App.Quit();
Console.WriteLine(presentation_text);
Console.ReadLine();
}
}
}

推荐答案

如果要使用Office互操作,则必须在服务器上安装 PowerPoint



否则,您需要一个能够读取PPT文件的库。



如果你的文件是OpenXML文件(扩展名 pttx ),你可以使用 Open XML SDK 2.5 for Office [ ^ ]。



如何:全部获取演示文稿中所有幻灯片中的文本(Open XML SDK) [ ^ ]似乎就是你想要的。
You have to install PowerPoint on the server if you want to use Office interop.

Otherwise you need a library that is able to read PPT files.

If your files are OpenXML files (extension pttx), you can use the Open XML SDK 2.5 for Office[^].

The How to: Get all the text in all slides in a presentation (Open XML SDK)[^] seems to be what you want.


通过Interop使用任何Office应用程序的问题在于它不支持非交互式登录会话,即:一个Web应用程序或Windows服务应用程序。



如果您要从任何Office文档中提取数据,那么使用OpenXml会好得多SDK而不是互操作。
The problem with using any Office app via Interop is that it's not supported in a non-interactive logon session, i.e.: a web app or Windows service app.

If you're going to pull data out of any Office document, it's far better to use the OpenXml SDK and not interop.


这篇关于有没有办法读取ppt数据并存储在SQL表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆