I'm building a table in reportlab and want some cells in a table to be displayed in the format "Example: some text", with part of the cell being bolded and the rest not. I'm wrapping each cell in Paragraph to allow for wrapping when lines are too long, but this doesn't provide a neat way to apply formatting to only part of the cell's contents. These are the unideal things I have tried:
- Use XML to apply the formatting to the first part of the cell's content, concatenate the string with the second part, and wrap the whole thing in
Paragraph; this is currently what I'm doing, and while it technically works, it isn't the prettiest code to look at, especially when working as part of the rest of my script. Relevant code (let me know if it needs more context):
cellData = (example, someText)
cellBold = "".join("<b>", cellData [0], "</b>", cellData [1])
tableRow.append(Paragraph(cellBold, normalStyle))
- Display both
Paragraphs in the same cell; I tried this in a similar manner described in the answer to this similar question, but doing so displayed the twoParagraphs on separate lines, instead of on the same line. This would work perfectly if there was a way to remove the line break at the end of aParagraph, but I don't think there is. Relevant code:
cellData = (example, someText)
tableRow.append([Paragraph(cellData [0], boldStyle), Paragraph(cellData [1], normalStyle)])
Two other solutions would be to be able to apply formatting to part of a Paragraph or to concanenate two Paragraphs, but I don't think these are possible in reportlab. Is there a way to neatly accomplish what I want, or do I have to stick with the code mess of using XML formatting on the strings themselves? I'm using the doc.build method of building my PDF, if that's relevant.