Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Mon Apr 01, 2024 2:39 pm

hi im using spire.doc 12.3.2 and vscode to devlope my university project
i want to write a bullet list of texts in a table cell and langue is right to left but bullet stay at left of my text
i tried TextDirection in my code but didnt work
Code: Select all
section.TextDirection = TextDirection.TopToBottomRotated
cell.CellFormat.TextDirection = TextDirection.TopToBottomRotated
paragraph.TextDirection = TextDirection.TopToBottomRotated


here is bullet list style from tutorial
Code: Select all
# Create a bulleted list style
listStyle = ListStyle(document, ListType.Bulleted)
listStyle.Name = "bulletedList"
listStyle.Levels[0].BulletCharacter = "\u00B7"
listStyle.Levels[0].CharacterFormat.FontName = "Symbol"
listStyle.Levels[0].TextPosition = 20
document.ListStyles.Add(listStyle)


at first i wonder why do TopToBottomRotated work properly for writing hoerizentaly
at second i dont know what should i do to set bullets at right

here is full code
Code: Select all
# report function
    def ExportWord(self, ):
        print("report")
        # check DraftCheckBox
        IsDraft = self.ui.DraftCheckBox.isChecked()
        print(IsDraft)
        # Create an object of the Document class
        document = Document()
       
        # Create a bulleted list style
        listStyle = ListStyle(document, ListType.Bulleted)
        listStyle.Name = "bulletedList"
        listStyle.Levels[0].BulletCharacter = "\u00B7"
        listStyle.Levels[0].CharacterFormat.FontName = "Symbol"
        listStyle.Levels[0].TextPosition = 20
        document.ListStyles.Add(listStyle)
       
        # Add blank page section
        section = document.AddSection()
       
        # Add header page section
        section = document.AddSection()
        section.TextDirection = TextDirection.TopToBottomRotated

        # Add a title
        titleParagraph = section.AddParagraph()
        titleParagraph.AppendText("اطلاعات سربرگ")
        titleParagraph.Format.HorizontalAlignment = HorizontalAlignment.Right
       
        # Apply heading1 to the title
        titleParagraph.ApplyStyle(BuiltinStyle.Heading1)

        # blank line
        bodyParagraph_1 = section.AddParagraph()
       
        # load assesment data
        i = self.FindAssesmntData(self.current_assesment.AssesmentID)
        AssesmentData = self.AssesmentsList[i]
        print(AssesmentData)

        # add table
        # Create a table
        table = section.AddTable(True)

        # Set the width of table
        table.PreferredWidth = PreferredWidth(WidthType.Percentage, int(100))

        # Set the border of table
        table.TableFormat.Borders.BorderType = BorderStyle.Single
        table.TableFormat.Borders.LineWidth = 1.0
        table.TableFormat.Borders.Color = Color.get_Black()

        # Add first row
        row = table.AddRow(False, 4)
        row.Height = 20.0
       
        # Add data to the cells
        cell = row.Cells[0]
        cell.CellFormat.VerticalAlignment = VerticalAlignment.Middle
        paragraph = cell.AddParagraph()
        paragraph.Format.HorizontalAlignment = HorizontalAlignment.Center
        paragraph.AppendText(AssesmentData[2])
        cell = row.Cells[1]
        cell.CellFormat.VerticalAlignment = VerticalAlignment.Middle
        paragraph = cell.AddParagraph()
        paragraph.Format.HorizontalAlignment = HorizontalAlignment.Center
        paragraph.AppendText("سازمان")
        cell = row.Cells[2]
        cell.CellFormat.VerticalAlignment = VerticalAlignment.Middle
        paragraph = cell.AddParagraph()
        paragraph.Format.HorizontalAlignment = HorizontalAlignment.Center
        paragraph.AppendText(AssesmentData[1])
        cell = row.Cells[3]
        cell.CellFormat.VerticalAlignment = VerticalAlignment.Middle
        paragraph = cell.AddParagraph()
        paragraph.Format.HorizontalAlignment = HorizontalAlignment.Center
        paragraph.AppendText("نام")
       
        # Add the second row
        row = table.AddRow(False, 4)
        row.Height = 20.0
        cell = row.Cells[0]
        cell.CellFormat.VerticalAlignment = VerticalAlignment.Middle
        paragraph = cell.AddParagraph()
        paragraph.Format.HorizontalAlignment = HorizontalAlignment.Center
        paragraph.AppendText(AssesmentData[4])
        cell = row.Cells[1]
        cell.CellFormat.VerticalAlignment = VerticalAlignment.Middle
        paragraph = cell.AddParagraph()
        paragraph.Format.HorizontalAlignment = HorizontalAlignment.Center
        paragraph.AppendText("تاریخ پایان")
        cell = row.Cells[2]
        cell.CellFormat.VerticalAlignment = VerticalAlignment.Middle
        paragraph = cell.AddParagraph()
        paragraph.Format.HorizontalAlignment = HorizontalAlignment.Center
        paragraph.AppendText(AssesmentData[3])
        cell = row.Cells[3]
        cell.CellFormat.VerticalAlignment = VerticalAlignment.Middle
        paragraph = cell.AddParagraph()
        paragraph.Format.HorizontalAlignment = HorizontalAlignment.Center
        paragraph.AppendText("تاریخ شروع")
       
        # Add the third row
        row = table.AddRow(False, 4)
        row.Height = 20.0
       
        # merge celes
        table.ApplyHorizontalMerge(2, 0, 1)
        table.ApplyHorizontalMerge(2, 2, 3)

        # add data
        cell = row.Cells[0]
        cell.CellFormat.VerticalAlignment = VerticalAlignment.Middle
        paragraph = cell.AddParagraph()
        paragraph.Format.HorizontalAlignment = HorizontalAlignment.Center
        paragraph.AppendText("ممیزین")
        cell = row.Cells[2]
        cell.CellFormat.VerticalAlignment = VerticalAlignment.Middle
        paragraph = cell.AddParagraph()
        paragraph.Format.HorizontalAlignment = HorizontalAlignment.Center
        paragraph.AppendText("تأمین کنندگان")
       
        # Add the forth row
        row = table.AddRow(False, 4)
        row.Height = 20.0
       
        # merge celes
        table.ApplyHorizontalMerge(3, 0, 1)
        table.ApplyHorizontalMerge(3, 2, 3)

        # add data
        cell = row.Cells[0]
        cell.CellFormat.HorizontalAlignment = HorizontalAlignment.Right
        cell.CellFormat.TextDirection = TextDirection.TopToBottomRotated
        auditors_list = eval(AssesmentData[6])
        for person_info in auditors_list:
            print(person_info)
            paragraph = cell.AddParagraph()
            paragraph.TextDirection = TextDirection.TopToBottomRotated
            paragraph.Format.HorizontalAlignment = HorizontalAlignment.Center
            paragraph.Format.HorizontalAlignment = HorizontalAlignment.Right
            paragraph.AppendText(f"{person_info[0]} | {person_info[1]}")
            paragraph.ListFormat.ApplyStyle("bulletedList")
            paragraph.ListFormat.ListLevelNumber = 0
       
        # paragraph = cell.AddParagraph()
        # paragraph.Format.HorizontalAlignment = HorizontalAlignment.Center
        # paragraph.AppendText()
        cell = row.Cells[2]
        cell.CellFormat.VerticalAlignment = VerticalAlignment.Middle
        paragraph = cell.AddParagraph()
        paragraph.Format.HorizontalAlignment = HorizontalAlignment.Center
        paragraph.AppendText(AssesmentData[7])



        # # Add the table to the section
        # section.Tables.Add(table)
       
        # Add Report for quality capability section
        section = document.AddSection()
        # Add two paragraphs
        bodyParagraph_1 = section.AddParagraph()
        bodyParagraph_1.AppendText("'گزارش کیفیت")
        bodyParagraph_1.Format.HorizontalAlignment = HorizontalAlignment.Right
       
        # add header
        # Get the first section
        section = document.Sections[0]

        # Get header
        header = section.HeadersFooters.Header

        # Add a paragraph to the header and set its alignment style
        headerParagraph = header.AddParagraph()
        headerParagraph.Format.HorizontalAlignment = HorizontalAlignment.Center
       
        # Add text to the header paragraph and set its font style
        text = headerParagraph.AppendText("گزارش ممیزی فرآیند\n")
        text.CharacterFormat.FontName = "IRANSansX"
        text.CharacterFormat.FontSize = 15
        # text.CharacterFormat.Bold = True
        # text.CharacterFormat.TextColor = Color.get_Blue()
       
        # Set the border of the header paragraph
        headerParagraph.Format.Borders.Bottom.BorderType = BorderStyle.Single
        headerParagraph.Format.Borders.Bottom.Space = 0.05


        # Save the resulting document
        document.SaveToFile("output/TextWatermark.docx")

        # # Close the Document object
        # document.Close()
       
        print("dpcumnet closed")
       
       
        # wateermark
        # # Create an object of the TextWatermark class
        # txtWatermark = TextWatermark()
        # # Set watermark text, font size, text color and layout
        # txtWatermark.Text = "پیش نویس"
        # txtWatermark.FontSize = 95
        # # txtWatermark.Color = Color.get_Red()
        # # txtWatermark.Layout = WatermarkLayout.Diagonal

        # # Set the text watermark as the watermark of the document
        # document.Watermark = txtWatermark


here is bullet list image
Image

regrads

XxLonely
 
Posts: 21
Joined: Sat Mar 30, 2024 5:11 pm

Tue Apr 02, 2024 7:41 am

Hi,

For your requirement that set bullet list in right to left, you needn’t set the section direction (section.TextDirection = TextDirection.TopToBottomRotated), but need to set the text direction in paragraph through the following code, set isBidi to ture indicate that the text direction is from right to left in paragraph:

Code: Select all
paragraph.Format.IsBidi = True



Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Wed Apr 03, 2024 11:06 am

Thank you very much for the advice
but the bullet charachter change from big soild circles to small dots
what should i change?
bullet style?
Image
here is bullet style
Code: Select all
# Create a bulleted list style
listStyle = ListStyle(document, ListType.Bulleted)
listStyle.Name = "bulletedList"
listStyle.Levels[0].BulletCharacter = "\u00B7"
listStyle.Levels[0].CharacterFormat.FontName = "Symbol"
listStyle.Levels[0].TextPosition = 20
document.ListStyles.Add(listStyle)


here is corrected full code
Code: Select all
    # report function
    def ExportWord(self, ):
        print("report")
        # check DraftCheckBox
        IsDraft = self.ui.DraftCheckBox.isChecked()
        print(IsDraft)
        # Create an object of the Document class
        document = Document()
       
        # Create a bulleted list style
        listStyle = ListStyle(document, ListType.Bulleted)
        listStyle.Name = "bulletedList"
        listStyle.Levels[0].BulletCharacter = "\u00B7"
        listStyle.Levels[0].CharacterFormat.FontName = "Symbol"
        listStyle.Levels[0].TextPosition = 20
        document.ListStyles.Add(listStyle)
       
        # Add blank page section
        section = document.AddSection()
       
        # Add header page section
        section = document.AddSection()

        # Add a title
        titleParagraph = section.AddParagraph()
        titleParagraph.AppendText("اطلاعات سربرگ")
        titleParagraph.Format.HorizontalAlignment = HorizontalAlignment.Right
       
        # Apply heading1 to the title
        titleParagraph.ApplyStyle(BuiltinStyle.Heading1)

        # blank line
        bodyParagraph_1 = section.AddParagraph()
       
        # load assesment data
        i = self.FindAssesmntData(self.current_assesment.AssesmentID)
        AssesmentData = self.AssesmentsList[i]
        print(AssesmentData)

        # add table
        # Create a table
        table = section.AddTable(True)

        # Set the width of table
        table.PreferredWidth = PreferredWidth(WidthType.Percentage, int(100))

        # Set the border of table
        table.TableFormat.Borders.BorderType = BorderStyle.Single
        table.TableFormat.Borders.LineWidth = 1.0
        table.TableFormat.Borders.Color = Color.get_Black()

        # Add first row
        row = table.AddRow(False, 4)
        row.Height = 20.0
       
        # Add data to the cells
        cell = row.Cells[0]
        cell.CellFormat.VerticalAlignment = VerticalAlignment.Middle
        paragraph = cell.AddParagraph()
        paragraph.Format.HorizontalAlignment = HorizontalAlignment.Center
        paragraph.AppendText(AssesmentData[2])
        cell = row.Cells[1]
        cell.CellFormat.VerticalAlignment = VerticalAlignment.Middle
        paragraph = cell.AddParagraph()
        paragraph.Format.HorizontalAlignment = HorizontalAlignment.Center
        paragraph.AppendText("سازمان")
        cell = row.Cells[2]
        cell.CellFormat.VerticalAlignment = VerticalAlignment.Middle
        paragraph = cell.AddParagraph()
        paragraph.Format.HorizontalAlignment = HorizontalAlignment.Center
        paragraph.AppendText(AssesmentData[1])
        cell = row.Cells[3]
        cell.CellFormat.VerticalAlignment = VerticalAlignment.Middle
        paragraph = cell.AddParagraph()
        paragraph.Format.HorizontalAlignment = HorizontalAlignment.Center
        paragraph.AppendText("نام")
       
        # Add the second row
        row = table.AddRow(False, 4)
        row.Height = 20.0
        cell = row.Cells[0]
        cell.CellFormat.VerticalAlignment = VerticalAlignment.Middle
        paragraph = cell.AddParagraph()
        paragraph.Format.HorizontalAlignment = HorizontalAlignment.Center
        paragraph.AppendText(AssesmentData[4])
        cell = row.Cells[1]
        cell.CellFormat.VerticalAlignment = VerticalAlignment.Middle
        paragraph = cell.AddParagraph()
        paragraph.Format.HorizontalAlignment = HorizontalAlignment.Center
        paragraph.AppendText("تاریخ پایان")
        cell = row.Cells[2]
        cell.CellFormat.VerticalAlignment = VerticalAlignment.Middle
        paragraph = cell.AddParagraph()
        paragraph.Format.HorizontalAlignment = HorizontalAlignment.Center
        paragraph.AppendText(AssesmentData[3])
        cell = row.Cells[3]
        cell.CellFormat.VerticalAlignment = VerticalAlignment.Middle
        paragraph = cell.AddParagraph()
        paragraph.Format.HorizontalAlignment = HorizontalAlignment.Center
        paragraph.AppendText("تاریخ شروع")
       
        # Add the third row
        row = table.AddRow(False, 4)
        row.Height = 20.0
       
        # merge celes
        table.ApplyHorizontalMerge(2, 0, 1)
        table.ApplyHorizontalMerge(2, 2, 3)

        # add data
        cell = row.Cells[0]
        cell.CellFormat.VerticalAlignment = VerticalAlignment.Middle
        paragraph = cell.AddParagraph()
        paragraph.Format.HorizontalAlignment = HorizontalAlignment.Center
        paragraph.AppendText("ممیزین")
        cell = row.Cells[2]
        cell.CellFormat.VerticalAlignment = VerticalAlignment.Middle
        paragraph = cell.AddParagraph()
        paragraph.Format.HorizontalAlignment = HorizontalAlignment.Center
        paragraph.AppendText("تأمین کنندگان")
       
        # Add the forth row
        row = table.AddRow(False, 4)
        row.Height = 20.0
       
        # merge celes
        table.ApplyHorizontalMerge(3, 0, 1)
        table.ApplyHorizontalMerge(3, 2, 3)

        # add data
        cell = row.Cells[0]
        cell.CellFormat.HorizontalAlignment = HorizontalAlignment.Left
        auditors_list = eval(AssesmentData[6])
        for person_info in auditors_list:
            print(person_info)
            paragraph = cell.AddParagraph()
            paragraph.Format.IsBidi = True
            paragraph.Format.HorizontalAlignment = HorizontalAlignment.Left
            paragraph.AppendText(f"{person_info[0]} | {person_info[1]}")
            paragraph.ListFormat.ApplyStyle("bulletedList")
            paragraph.ListFormat.ListLevelNumber = 0


        cell = row.Cells[2]
        cell.CellFormat.HorizontalAlignment = HorizontalAlignment.Left
        suppliers_list = eval(AssesmentData[7])
        for person_info in suppliers_list:
            print(person_info)
            paragraph = cell.AddParagraph()
            paragraph.Format.IsBidi = True
            paragraph.Format.HorizontalAlignment = HorizontalAlignment.Left
            paragraph.AppendText(f"{person_info[0]} | {person_info[1]}")
            paragraph.ListFormat.ApplyStyle("bulletedList")
            paragraph.ListFormat.ListLevelNumber = 0



        # # Add the table to the section
        # section.Tables.Add(table)
       
        # Add Report for quality capability section
        section = document.AddSection()
        # Add two paragraphs
        bodyParagraph_1 = section.AddParagraph()
        bodyParagraph_1.AppendText("'گزارش کیفیت")
        bodyParagraph_1.Format.HorizontalAlignment = HorizontalAlignment.Right
       
        # add header
        # Get the first section
        section = document.Sections[0]

        # Get header
        header = section.HeadersFooters.Header

        # Add a paragraph to the header and set its alignment style
        headerParagraph = header.AddParagraph()
        headerParagraph.Format.HorizontalAlignment = HorizontalAlignment.Center
       
        # Add text to the header paragraph and set its font style
        text = headerParagraph.AppendText("گزارش ممیزی فرآیند\n")
        text.CharacterFormat.FontName = "IRANSansX"
        text.CharacterFormat.FontSize = 15
        # text.CharacterFormat.Bold = True
        # text.CharacterFormat.TextColor = Color.get_Blue()
       
        # Set the border of the header paragraph
        headerParagraph.Format.Borders.Bottom.BorderType = BorderStyle.Single
        headerParagraph.Format.Borders.Bottom.Space = 0.05


        # Save the resulting document
        document.SaveToFile("output/TextWatermark.docx")

        # # Close the Document object
        # document.Close()
       
        print("dpcumnet closed")



regards

XxLonely
 
Posts: 21
Joined: Sat Mar 30, 2024 5:11 pm

Thu Apr 04, 2024 2:53 am

Hi,

Thanks for your feedback.
I tested your full code indeed found the issue that the big soild circles became to small dots. This issue has been logged into our bug trackings system with the issue ID: SPIREDOC-10417. I will keep you informed once any progress has been made. Apologize for the inconvenience caused.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1379
Joined: Tue Sep 27, 2016 1:06 am

Thu Apr 04, 2024 1:35 pm

thank you i will wait

XxLonely
 
Posts: 21
Joined: Sat Mar 30, 2024 5:11 pm

Return to Spire.Doc