gitbrent / PptxGenJS

Create PowerPoint presentations with a powerful, concise JavaScript API.
https://gitbrent.github.io/PptxGenJS/
MIT License
2.84k stars 625 forks source link

I am trying to add shape before each table row but I am not able to position it properly #1253

Open secabhi opened 1 year ago

secabhi commented 1 year ago

I am trying to add bullet shapes with different color before each row of table horizontally centrally aligned.

code

`let pptx = new PptxGenJS(); const targetData = [ "Taget1", "Taget1sf sdfsfsdf", "Taget1as dasdas asdasdasd", "Taget1", "Taget1as dasdasd asdadas", "Taget1", "Taget1asd asdasdas dasdsadas asdasd", "Taget1" ]; let slide = pptx.addSlide({ sectionTitle: "Tables" });

const tableData = []; for (let i = 0; i <= targetData.length; i++) { const rowData = []; // add bullet in first column for (let j = 2; j <= targetData.length; j++) { rowData.push({ text: ${targetData[i]}, options: { valign: "center" } }); } tableData.push(rowData); }

slide.addTable(tableData, { x: 0.5, y: 0.5, w: 9, rowH: 0.25, height:'100%', margin: 0, fill: "F7F7F7", valign: "center", align: "center", border: { pt: 1, color: "BDBDBD" } });

const rowHeight = 0.25; const startPos = 0.5; const tableWidth = 9; const shapeWidth = 0.1; let y = startPos; for (let i = 0; i < targetData.length; i++) { const word = targetData[i]; const count = Math.ceil(word.length / 10); console.log('count----',count) y = y + (rowHeight * i) + (rowHeight / 2); const x = (tableWidth - shapeWidth) / 2; console.log('yyy----',i,y) slide.addShape(pptx.shapes.RECTANGLE, { x: 0.5, y: y, w: shapeWidth, h: 0.1, fill: { color: pptx.colors.ACCENT1 } }); }`

but the y position is not coming central aligned horizontally center aligned