你可以通过公式BC_QRCODE来创建一个QR Code: =BC_QRCODE(value, color, backgroudColor, errorCorrectionLevel, model, version, mask, connection, connectionNo, charCode, charset, quietZoneLeft, quietZoneRight, quietZoneTop, quietZoneBottom)
公式包含以下参数:
errorCorrectionLevel : 表示编码使用的QRCode错误校验等级(默认值是 'L') ,值为'L', 'M', 'Q', 或 'H'
model : 表示编码使用的模式(默认值是 2),值为 1 或 2
version : 表示编码使用的版本(默认值是 'auto') ,值为'auto', 1-14, 或 1-40',对于模式1来说,版本的范围在 1-14, 而对于模式2来说,版本的范围在1-40
mask : 表示编码使用的掩码 (默认值是 'auto'), 值为 'auto' 或 0-7
connection : 表示是否使用链接编码(默认值是 false)
connectionNo : 表示链接编码中索引值(默认值是 '0'), 值为 0-15
charCode : 表示编码使用的字符集.
charset : 表示编码使用的编码集(默认值是 'UTF-8'),值为 'UTF-8' 或 'Shift-JIS'.
window.onload = function () {
var spread = new GC.Spread.Sheets.Workbook(document.getElementById('ss'), { sheetCount: 1 });
initSpread(spread);
};
var FORMULA = 'BC_QRCODE';
function initSpread(spread) {
var sheet = spread.getSheet(0);
spread.suspendPaint();
_initBasicSheet(sheet);
spread.resumePaint();
}
function _initBasicSheet(sheet) {
sheet.name('customSheet');
_setData(sheet);
_setStyle(sheet);
for (var row = 3; row < 6; row++) {
sheet.setFormula(row, 3, '=' + FORMULA + '(C' + (row + 1) + ')');
sheet.setFormula(row, 4, '=' + FORMULA + '(C' + (row + 1) + ',,,"H")');
sheet.setFormula(row, 5, '=' + FORMULA + '(C' + (row + 1) + ',,,,1)');
sheet.setFormula(row, 6, '=' + FORMULA + '(C' + (row + 1) + ',,,,,8)');
sheet.setFormula(row, 7, '=' + FORMULA + '(C' + (row + 1) + ',,,,,,3)');
sheet.setFormula(row, 8, '=' + FORMULA + '(C' + (row + 1) + ',,,,,,,"true",0)');
sheet.setFormula(row, 9, '=' + FORMULA + '(C' + (row + 1) + ',,,,,,,"true",1)');
}
}
function _setStyle(sheet) {
for (var row = 3; row < 6; row++) {
sheet.setRowHeight(row, 80);
}
sheet.setColumnWidth(0, 20);
for (var col = 1; col < 3; col++) {
sheet.setColumnWidth(col, 160);
}
for (var col = 3; col < 10; col++) {
sheet.setColumnWidth(col, 120);
}
sheet.setColumnWidth(10, 200);
sheet.setColumnWidth(4, 200);
sheet
.getRange(1, 1, 2, 10)
.foreColor('#000')
.backColor('#FFF3CE')
.setBorder(new GC.Spread.Sheets.LineBorder('orange', GC.Spread.Sheets.LineStyle.thin), { all: true });
sheet
.getRange(1, 1, 5, 10)
.vAlign(GC.Spread.Sheets.VerticalAlign.center)
.hAlign(GC.Spread.Sheets.HorizontalAlign.center)
.setBorder(new GC.Spread.Sheets.LineBorder('orange', GC.Spread.Sheets.LineStyle.medium), { outline: true });
sheet.getRange(1, 1, 1, 9).foreColor('#000').backColor('#FFF3CE').wordWrap(true);
sheet.getRange(1, 2, 5, 1).wordWrap(true);
sheet.getCell(3, 10).value('No QR Code generated, barcode data is too short to create connection symbol.').wordWrap(true).foreColor("red");
sheet.getCell(4, 10).value('No QR Code generated, barcode data is too short to create connection symbol.').wordWrap(true).foreColor("red");
sheet.addSpan(2, 8, 1, 2);
}
function _setData(sheet) {
var headers = [[
'Default',
'Change errorCorrectionLevel',
'Change model',
'Change version',
'Change mask',
'Change connection and connectionNo ',
'',
'Explain'
]];
sheet.setArray(2, 3, headers)
var dataArray = [
['Police', 911],
['Travel Info Call 511', 511],
['', 'abcdefghijklmnopqrstuvwxyz1234567890']
];
sheet.setArray(3, 1, dataArray);
sheet.addSpan(1, 1, 2, 1);
sheet.addSpan(1, 2, 2, 1);
sheet.addSpan(1, 3, 1, 7);
sheet.setValue(1, 1, 'Service');
sheet.setValue(1, 2, 'Number');
sheet.setValue(1, 3, 'QR Code');
}
<!doctype html>
<html style="height:100%;font-size:14px;">
<head>
<meta name="spreadjs culture" content="zh-cn" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css"
href="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets/dist/gc.spread.sheets.all.min.js"
type="text/javascript"></script>
<script
src="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets-barcode/dist/gc.spread.sheets.barcode.min.js"
type="text/javascript"></script>
<script
src="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets-resources-zh/dist/gc.spread.sheets.resources.zh.min.js"
type="text/javascript"></script>
<script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script>
<script src="app.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div class="sample-tutorial">
<div id="ss" class="sample-tutorial"></div>
</div>
</body>
</html>
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}