读取ppt并存入数据库_有没有办法读取ppt数据并存储在SQL表中

bd96500e110b49cbb3cd949968f18be7.png

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();

}

}

}

解决方案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.

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值