Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot Change Font's isBold and LatinName in the Table Cell #669

Closed
FrenkieWang opened this issue May 8, 2024 · 2 comments
Closed

Cannot Change Font's isBold and LatinName in the Table Cell #669

FrenkieWang opened this issue May 8, 2024 · 2 comments
Assignees
Labels
bug This issue is a bug

Comments

@FrenkieWang
Copy link

FrenkieWang commented May 8, 2024

Hello, I found there is a Bug in ShapeCrawler.
I cannot the attribute isBold, LatinName and OffsetEffect of the Text in a Table Cell.

For example, in the code below.

using System;
using System.IO;
using ShapeCrawler;

class Program
{
    static void Main(string[] args)
    {
        // Create a new PPT and gets its First Slide
        var pres = new Presentation();
        ISlide slide = pres.Slides[0];

        // Create a Table and get the Table
        slide.Shapes.AddTable(40, 40, 6, 5);
        var table = (ITable)slide.Shapes.Last();

        // Add text into a Table Cell
        var cell = table[1, 2];
        cell.TextFrame.Text = "Hello";

        // Edit the Text Font in the Table Cell
        var cellFont = cell.TextFrame.Paragraphs.First().Portions.First().Font;
        cellFont.Size = 40;
        cellFont.LatinName = "Prelo Slab Bold";

        // Get the Path of Desktop
        string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

        // Assgin the complete Path to save PPT File
        string pptFilePath = Path.Combine(desktopPath, "Text1.pptx");
        pres.SaveAs(pptFilePath);

        Console.WriteLine($"PPT has been saved to:{pptFilePath}");
    }
}

I created a Table and get the Table Cell in Row 2, Column 3.
I added a Text Hello in that Table Cell.

I can only change the Font Size of Hello.
However, if I try to change the Font's LatinName,
it will always throws an Exception in Line 24,
which states Sequence contains no Element
Font Exception2

I used BreakPoint to debug, I found that Exception will occur in the three attributes of Font:

  1. isBold
  2. LatinName
  3. OffsetEffect
    Font Exception

The Exception is located at System.Linq.Enumerable.First[TSource].
Font Exception3

Therefore, I am sure that the Original Code of ShapeCrawler has some bugs
It cannot change the isBold, LatinName and OffsetEffect of the Text in a Table Cell.

@ashahabov ashahabov added the bug This issue is a bug label May 12, 2024
@ashahabov
Copy link
Member

@FrenkieWang, thank you for the bug report. I was able to reproduce the issue.

@ashahabov
Copy link
Member

Minimum code for repro:

var pres = new Presentation();
var slide = pres.Slides[0];
slide.Shapes.AddTable(40, 40, 6, 5);
var table = (ITable)slide.Shapes.Last();
var cell = table[1, 2];
cell.TextFrame.Text = "Test";
var cellFont = cell.TextFrame.Paragraphs.First().Portions.First().Font;

cellFont.LatinName = "Arial";

@ashahabov ashahabov added help wanted Maintainer wants help on this issue good first issue This issue is a good issue for first-time contributors labels May 12, 2024
@ashahabov ashahabov self-assigned this Aug 18, 2024
@ashahabov ashahabov removed help wanted Maintainer wants help on this issue good first issue This issue is a good issue for first-time contributors labels Aug 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug
Projects
Status: Done
Development

No branches or pull requests

2 participants