Print custom text
When printing in Excel, specific characters are added to the top of the grid and printed.
userCellsCallback settings
userCellsCallback is used to change the position of a cell by referring to the number of output columns and rows. Setting style properties is the same as applying CSS styles.
gridView.exportGrid({
type: "excel",
target: "local",
fileName: "gridExportSample.xlsx",
yOffset: 5;
userCellsCallback: function (grid, rowCount, colCount, sheetName) {
return [
{
row: 2,
col: colCount - 4,
value: "Payment",
mergeRow: 2;
heights: [15, 30],
styles: { textAlign: "center", border: "1px solid black" },
},
{
row: 2,
col: colCount - 3,
value: "Team Leader",
height: 15,
styles: { textAlign: "center", border: "1px solid black" },
},
{
row: 3,
col: colCount - 3,
value: "",
height: 30,
styles: { border: "1px solid black" },
},
{
row: 2,
col: colCount - 2,
value: "Manager",
height: 15,
styles: { textAlign: "center", border: "1px solid black" },
},
{
row: 3,
col: colCount - 2,
value: "",
height: 30,
styles: { border: "1px solid black" },
},
{
row: 2,
col: colCount - 1,
value: "Representative",
height: 15,
styles: { textAlign: "center", border: "1px solid black" },
},
{
row: 3,
col: colCount - 1,
value: "",
height: 30,
styles: { border: "1px solid black" },
},
];
},
done: function () {
alert("done excel export");
},
});
userCells settings
Use userCells to display specific characters in a fixed area.
var userCells = [
{ row: 0, col: 0, value: "User input string" },
{ row: 1, col: 0, styleName: "orangeFontColor", value: "Apply style" },
{
row: 2,
col: 0,
mergeRow: 1;
mergeCol: 3;
styleName: "orangeFontColor",
value: "Merge and apply style.",
},
{
row: 3,
col: 0,
mergeRow: 2;
mergeCol: 3;
value: "inline-style",
styles: { background: "red", fontSize: "20px" },
},
{
row: 5,
col: 1,
value: 12345,
format: "#,##0.0_ ",
styles: { textAlign: "right" },
},
{
row: 5,
col: 4,
value: new Date(2022, 4, 16),
format: "[$-F800]dddd, mmmm dd, yyyy",
styles: { textAlign: "center" },
},
];
gridView.exportGrid({
type: "excel",
target: "local",
yOffset: 6;
userCells: userCells,
});