Windows下可利用word的COM组件,调用Word软件生成docx文件,在Linux下没有MS Word也没有COM组件,所以只能直接写openXML格式的方式生成。
WPS,MSWord均支持openXML,用户操作与docx完全一致。
支持文字、表格和图片的处理,目前不支持表格合并。
段落支持左对齐、右对齐、居中对齐及两端对齐,两端对齐模式下,首行自动缩进。
内容写完后,需调用endDocument函数。
table*系列函数应严格按次序调用,或者准备好内容后,调用addTable函数一次性绘制表格。
需要cpp源代码的可留言或私信。
class WordWriter : public QXmlStreamWriter
{
public:
WordWriter(QFile& file);
typedef enum{Align_Left, Align_Center, Align_Right, Align_Both} Para_Align;
void endDocument();
void addParagraph(QString strText, Para_Align align= Align_Both, QString strFont="宋体", int nFontHeight=28);
void table_begin(int nCols, double cmWidths[]); // sum of widths should be 8425
void table_beginRow();
void table_endRow();
void table_setCell(QString strText, double cmWidth, Para_Align align= Align_Both, QString strFont="宋体", int nFontHeight=28);
void table_end();
void addTable(int nCols, double cmWidths[], QVector<QStringList> contents,bool bAutoAlign = true,QString strFont="宋体", int nFontHeight=28);
void addImage(QString strImageFileName, double cmWidth, double cmHeight);
private:
int m_iImageId;
int m_irId;
struct ImgInfo
{
int iId;
int rId;
QString strFile;
QString strType;
};
QVector<ImgInfo> m_images;
};