PDA

View Full Version : باز کردن فایل پاورپوینت در سی شارپ



Mosafers
شنبه 06 آبان 1396, 16:12 عصر
سلام من میخوام توی سی شارپ یه فایل پاوپوینت باز کنم بیش از 3 ساعته یه کد درست پیدا نمیکنم منم مهارت کافی در این زمینه را ندارم لطفا راهنمایی کنید چطور باید استفاده کنم.
همگی به این گیر دادن : MsoTriState.msoTrue نمیتونم کتابخونش رو از کجا باید اضاف کرد جستجو کردم نتیجه نگرفتم.

نمونه کد من

Microsoft.Office.Interop.PowerPoint.Application ppApp = new Microsoft.Office.Interop.PowerPoint.Application(); ppApp.Visible = MsoTriState.msoTrue;
Presentations ppPresens = ppApp.Presentations;
Presentation objPres = ppPresens.Open(e.FullPath, MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue);
Slides objSlides = objPres.Slides;
Microsoft.Office.Interop.PowerPoint.SlideShowWindo ws objSSWs; Microsoft.Office.Interop.PowerPoint.SlideShowSetti ngs objSSS;
//Run the Slide show
objSSS = objPres.SlideShowSettings;
objSSS.Run();
objSSWs = ppApp.SlideShowWindows;
while (objSSWs.Count >= 1)
System.Threading.Thread.Sleep(100);
//Close the presentation without saving changes and quit PowerPoint
objPres.Close();
ppApp.Quit();


یا این:

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\myPowerpoint.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);

danialafshari
شنبه 06 آبان 1396, 17:10 عصر
با سلام
شما باید قبلش رفرنس های زیر رو به پروژه اضافه کنید


office
Microsoft.Office.Interop.PowerPoint

سپس در using:

using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;

موفق باشید

Mosafers
شنبه 06 آبان 1396, 18:05 عصر
واقعا ممنونم خیلی لطف کردید از این بهتر نمیشد :قلب:
من قسمت office را اضاف نکرده بودم توی سایت ها هم نگفته بودم این رفرنس رو باید اضاف کرد.
تشکر