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;