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

Table in tabel: The inner version is not rendering the correct structure so it doesn't seem to work like that. #2724

Open
NguyenBa1410 opened this issue Sep 13, 2024 · 0 comments

Comments

@NguyenBa1410
Copy link

NguyenBa1410 commented Sep 13, 2024

async generateSaudiHealthCertSeafoodDocx(
    query: HealthCertFoodDto,
    sellerStaff: Staff,
  ) {
    const PHONE_NUMBER = '07534563401';
    const PROFILE_URL = 'https://www.linkedin.com/in/dolan1';
    const EMAIL = 'docx@com';

    try {
      const pageWidth = 11908.8;
      const marginSize = 720;
      const displaySize = pageWidth - marginSize * 2;
      const widthIndex = 720;
      const borderNone: ITableCellBorders = {
        top: { style: 'single', color: 'FFFFFF' },
        bottom: { style: 'single', color: 'FFFFFF' },
        left: { style: 'single', color: 'FFFFFF' },
        right: { style: 'single', color: 'FFFFFF' },
      };
      const doc = new Document({
        styles: {
          paragraphStyles: [
            {
              id: 'normalPara',
              name: 'Normal Para',
              basedOn: 'Normal',
              quickFormat: true,
              run: {
                font: 'Calibri',
                size: 12,
              },
              paragraph: {
                spacing: {
                  line: 240,
                  before: 0,
                  after: 0,
                },
                rightTabStop: TabStopPosition.MAX,
                leftTabStop: 453.543307087,
              },
            },
            {
              id: 'boldPara',
              name: 'Bold Para',
              basedOn: 'Bold',
              quickFormat: true,
              run: {
                font: 'Calibri',
                size: 18,
                bold: true,
              },
              paragraph: {
                spacing: {
                  line: 240,
                  before: 0,
                  after: 0,
                },
                rightTabStop: TabStopPosition.MAX,
                leftTabStop: 453.543307087,
              },
            },
          ],
        },
        sections: [
          {
            properties: {
              page: {
                margin: {
                  top: marginSize,
                  left: marginSize,
                  right: marginSize,
                  bottom: marginSize,
                },
              },
            },
            children: [
              new Table({
                columnWidths: [displaySize / 2, displaySize / 2],
                rows: [
                  new TableRow({
                    children: [
                      new TableCell({
                        borders: borderNone,
                        children: [
                          new Paragraph({
                            children: [
                              new TextRun({
                                text: 'Health Certificate for Export of Products of Aquatic Animal Origin to the Kingdom of Saudi Arabia (KSA)',
                                color: 'FF0000',
                              }),
                            ],
                            style: 'boldPara',
                            alignment: AlignmentType.CENTER,
                          }),
                        ],
                      }),
                      new TableCell({
                        borders: borderNone,
                        children: [
                          new Paragraph({
                            children: [
                              new TextRun({
                                text: 'الشهادة صحية لتصدير املنتجات البحرية ذات أصل حيواني إلى اململكة العربية السعودية',
                                color: 'FF0000',
                              }),
                            ],
                            style: 'boldPara',
                            alignment: AlignmentType.CENTER,
                            bidirectional: true,
                          }),
                        ],
                      }),
                    ],
                  }),
                ],
              }),
              new Table({
                columnWidths: [
                  widthIndex,
                  displaySize / 2 - widthIndex,
                  widthIndex,
                  displaySize / 2 - widthIndex,
                ],
                rows: [
                  new TableRow({
                    children: [
                      new TableCell({
                        children: [
                          new Paragraph({
                            text: 'I.1',
                            style: 'boldPara',
                          }),
                        ],
                      }),
                      new TableCell({
                        children: [
                          new Table({
                            rows: [
                              new TableRow({
                                children: [],
                              }),
                            ],
                          }),
                          new Paragraph({
                            children: [
                              new TextRun({
                                text: 'Consignor (Exporter)',
                              }),
                              new TextRun({
                                text: '\t', // Khoảng cách giữa các đoạn văn
                              }),
                              new TextRun({
                                text: 'المرسل (المصدر)',
                              }),
                            ],
                            style: 'boldPara',
                          }),
                        ],
                      }),
                      new TableCell({
                        children: [
                          new Paragraph({
                            text: 'I.2',
                            style: 'boldPara',
                          }),
                        ],
                      }),
                      new TableCell({
                        children: [
                          new Paragraph({
                            text: 'Certificate Reference No.',
                            style: 'boldPara',
                          }),
                        ],
                      }),
                    ],
                  }),
                ],
              }),
            ],
          },
        ],
      });

      const file = await Packer.toBuffer(doc);

      return file;
    } catch (error) {
      console.error('Error generating document:', error);
      throw new Error('Document generation failed');
    }
  }`

new TableCell({
                        children: [
                          new Table({
                            rows: [
                              new TableRow({
                                children: [],
                              }),
                            ],
                          }),
                          new Paragraph({
                            children: [
                              new TextRun({
                                text: 'Consignor (Exporter)',
                              }),
                              new TextRun({
                                text: '\t', // Khoảng cách giữa các đoạn văn
                              }),
                              new TextRun({
                                text: 'المرسل (المصدر)',
                              }),
                            ],
                            style: 'boldPara',
                          }),
                        ],
                      }),

The internal tableCell seems to be malfunctioning and it has lost all the structure of a table.

Thank you for raising an issue to docx

Please do not raise an issue unless it is an issue.

  • Is your issue a feature request? Are you giving ideas to the community? Are you asking for help? Please raise a ticket in the Discussions section:

    https://github.com/dolanmiu/docx/discussions

  • Is your issue a previously asked? Please respond to that thread instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant