1

ppt ファイルのスライドですべての図形を取得しています。これらの図形からテキストを取得したいのですが、どうすればよいですか

これは、pptファイルですべてのスライドの形状を取得している私の方法です

public void Main(string[] args)
    {
        // The path to the documents directory.
        string dataDir = Path.GetFullPath(@"C:\Users\Vipin\Desktop\");
        //Load the desired the presentation
        Presentation pres = new Presentation(dataDir + "Android.ppt");
        using (Presentation prestg = new Presentation(dataDir + "Android.ppt"))
        {


            //Accessing a slide using its slide index
            int slideCount = prestg.Slides.Count();
            for (int i = 0; i <= slideCount - 1; i++)
            {
                ISlide slide = pres.Slides[i];
                foreach (IShape shap in slide.Shapes)
                {
                    int slideCountNumber = i + 1;

                    float shapeHeight = shap.Frame.Height;
                    float shapeWidth = shap.Frame.Width;
                    Debug.Write("slide Number: " + slideCountNumber + " shape width = " + shapeWidth + " shapeHeight = " + shapeHeight);

                }
            }

        }
    }

今、私はそれからテキストを取得できますか

4

2 に答える 2

0

すべての図形からテキストを抽出するのではなく、代わりにテキスト フレームからテキストを抽出したい場合があります。これを行うには、クラスGetAllTextFramesによって公開された静的メソッドを使用しますPresentationScanner

using (Presentation prestg = new Presentation(dataDir + "Android.ppt"))
{
   //Get an Array of ITextFrame objects from all slides in the PPTX
   ITextFrame[] textFramesPPTX = Aspose.Slides.Util.SlideUtil.GetAllTextFrames(pptxPresentation, true);

   //Loop through the Array of TextFrames
   for (int i = 0; i < textFramesPPTX.Length; i++)

   //Loop through paragraphs in current ITextFrame
   foreach (IParagraph para in textFramesPPTX[i].Paragraphs)

       //Loop through portions in the current IParagraph
       foreach (IPortion port in para.Portions)
       {
           //Display text in the current portion
           Console.WriteLine(port.Text);

           //Display font height of the text
           Console.WriteLine(port.PortionFormat.FontHeight);

           //Display font name of the text
           if (port.PortionFormat.LatinFont != null)
               Console.WriteLine(port.PortionFormat.LatinFont.FontName);
       }

ドキュメントを見る

于 2015-03-12T14:45:32.347 に答える