var orientation = spread.sheets[0].printInfo().orientation();
if (orientation == 2) {
printInfo.orientation(GC.Spread.Sheets.Print.PrintPageOrientation.landscape);
} else {
printInfo.orientation(GC.Spread.Sheets.Print.PrintPageOrientation.portrait);
}
以下是我全部的代码
<script type="text/javascript">
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("printArea1"));
var excelIo = new GC.Spread.Excel.IO();
var excelFilePath = "https://localhost:7218/EXCEL/test1.xlsx";
var xhr = new XMLHttpRequest();
xhr.open('GET', excelFilePath, true);
xhr.responseType = 'blob';
xhr.onload = function (e) {
if (this.status == 200) {
// get binary data as a response
var blob = this.response;
// convert Excel to JSON
excelIo.open(blob, function (json) {
var workbookObj = json;
spread.fromJSON(workbookObj);
}, function (e) {
// process error
alert(e.errorMessage);
}, {});
}
};
xhr.send();
//spread.name = "555.xlsx";
document.getElementById('print1').onclick = function () {
var sheet = spread.sheets[0];
var printInfo = sheet.printInfo();
printInfo.showRowHeader(GC.Spread.Sheets.Print.PrintVisibilityType.hide);
printInfo.showColumnHeader(GC.Spread.Sheets.Print.PrintVisibilityType.hide);
var margintop = printInfo.margin().top;
var marginbottom = printInfo.margin().bottom;
var marginleft = printInfo.margin().left;
var marginright = printInfo.margin().right;
var marginheader = printInfo.margin().header;
var marginfooter = printInfo.margin().footer;
printInfo.margin({ top: 20, bottom: 20, left: 20, right: 20, header: 1, footer: 1 });
printInfo.showBorder(false);
var printHeaderRight = printInfo.pageHeaderFooter().normal.header.right;
printHeaderRight = printHeaderRight.replaceAll("\r\n", "")
var printFootRight = printInfo.pageHeaderFooter().normal.footer.right;
if (printFootRight == "&F") {
printFootRight = "調査計画表(2)_51_00_20241122145348.xlsx";
}
var orientation = spread.sheets[0].printInfo().orientation();
if (orientation == 2) {
printInfo.orientation(GC.Spread.Sheets.Print.PrintPageOrientation.landscape);
} else {
printInfo.orientation(GC.Spread.Sheets.Print.PrintPageOrientation.portrait);
}
printInfo.pageHeaderFooter({
normal: {
header: {
left: "",
center: "",
right: printHeaderRight
},
footer: {
center: "",
right: '調査計画表(2)_51_00_20241122145348.xlsx'
}
}
});
//spread.name = "555.xlsx";
spread.print();
};
document.getElementById('save1').onclick = function () {
var worksheet = spread.sheets[0];
worksheet.getPageSetup().setIsPercentScale(false);
worksheet.getPageSetup().setFitToPagesWide(1);
worksheet.isPrintLineVisible(true);
spread.export(function (blob) {
saveAs(blob, "sss.xlsx");
}, function (e) {
console.log(e);
}, {
fileType: GC.Spread.Sheets.FileType.excel
});
};
document.getElementById('test').onclick = function () {
$("#PageForm").attr("action", "Home/Privacy");
$("#PageForm").submit();
}
</script>
|