QXlsx::Document xlsx;
1. Set column width or row height:
函数原型:
bool Document::setColumnWidth(int column, double width)
示例:
xlsx.setColumnWidth(第几列, 列宽);
函数原型:
bool Document::setColumnWidth(int colFirst, int colLast, double width)
示例:
xlsx.setColumnWidth(开始列, 结束列, 列宽);
xlsx.setRowHeight(第几行, 行高);
xlsx.setRowHeight(第几行, 结束行, 行高);
example
1.1 Write to the form
函数原型:
bool write(const CellReference &cell, const QVariant &value, const Format &format = Format());
参数1:单元格名;参数2:单元格的值;参数3:单元格格式
xlsx.write("A1", "FB3:电力安全工器具台账");
合并单元格:
xlsx.mergeCells("A1:N1", titleFormat);
2. Set the cell style:
QXlsx::Format titleFormat;
2.1 Set vertical alignment format
函数原型:
void Format::setVerticalAlignment(VerticalAlignment align)
示例:
titleFormat.setVerticalAlignment(Format::VerticalAlignment::AlignVCenter);//格式垂直居中
垂直对齐各种样式如下:
enum VerticalAlignment {
AlignTop, //顶端对齐
AlignVCenter, //垂直居中
AlignBottom, //底部对齐
AlignVJustify, //两端对齐
AlignVDistributed
};
2.2 Set the horizontal alignment format
示例:
titleFormat.setHorizontalAlignment(Format::VerticalAlignment::AlignLeft);
水平对齐各种样式如下:
enum HorizontalAlignment {
AlignHGeneral,
AlignLeft, //左对齐
AlignHCenter,//水平居中对齐
AlignRight, //右对齐
AlignHFill,
AlignHJustify,
AlignHMerge,
AlignHDistributed
};
2.3 Font size and boldness
titleFormat.setFontBold(true); //加粗
titleFormat.setFontSize(8); //字体大小为8
As shown in the following rain, some contrasts are bold and not added, the second and third lines in the middle are 14 fonts, and the rest are 8 fonts
2.3 Set the border style, automatic line wrapping, etc.
Format headerFormat;
Effects of not setting:
add thin border
headerFormat.setBorderStyle(Format::BorderThin);
word wrap
headerFormat.setTextWarp(true);//自动换行
After setting:
the border style is as follows:
enum BorderStyle {
BorderNone, //无边框,默认
BorderThin, //薄边框
BorderMedium,
BorderDashed, //虚线边框
BorderDotted, //点线边框
BorderThick,
BorderDouble,
BorderHair,
BorderMediumDashed,
BorderDashDot,
BorderMediumDashDot,
BorderDashDotDot,
BorderMediumDashDotDot,
BorderSlantDashDot
};