Overview

There are 11 types of barcode sparklines supported in SpreadJS, and they can be added using a simple formula.

To add a barcode to worksheet, you can using a simple barcode formula, for example: There are some common parameters of the barcode sparkline formulas, which are defined as follows: value: this string represents the encode on the symbol of barcode. color: (default value is 'rgb(0,0,0)') this color represents the barcode color. backgroundColor: (default value is 'rgb(255, 255, 255)') this color represents the barcode backgroundColor. showLabel: this value indicates whether to show the label text if the barcode as a label. labelPosition: this value represents the label position if the label is shown. fontFamily: (default value is 'sans-serif') this string represents the label text fontFamily. fontStyle: (default value is 'normal') this string represents the label text fontStyle. fontWeight: (default value is 'normal') this string represents the label text fontWeight. textDecoration: (default value is 'none') this string represents the label text textDecoration. textAlign: (default value is 'center') this string represents the label text textAlign. textSize: (default value is '12px') this string represents the label text textSize. quietZoneLeft: this value represents the size of left quiet zone. quietZoneRight: this value represents the size of right quiet zone. quietZoneTop: this value represents the size of top quiet zone. quietZoneBottom: this value represents the size of bottom quiet zone.
import * as React from 'react'; import * as ReactDOM from 'react-dom'; import './styles.css'; import { AppFunc } from './app-func'; import { App } from './app-class'; // 1. Functional Component sample ReactDOM.render(<AppFunc />, document.getElementById('app')); // 2. Class Component sample // ReactDOM.render(<App />, document.getElementById('app'));
import * as React from 'react'; import * as ReactDOM from 'react-dom'; import GC from '@mescius/spread-sheets'; import '@mescius/spread-sheets-barcode'; import { SpreadSheets, Worksheet, Column } from '@mescius/spread-sheets-react'; import './styles.css'; const Component = React.Component; const GCsheets = GC.Spread.Sheets; const FORMULA = 'BC_PDF417'; function _getElementById(id) { return document.getElementById(id); } export function AppFunc() { let spread = null; let autoGenerateColumns = true; let initSpread = function(value) { spread = value; spread.suspendPaint(); let sheet = spread.getSheet(0); sheet.name('customSheet'); _setData(sheet); _setStyle(sheet); let types = [ 'BC_QRCODE', 'BC_DataMatrix', 'BC_PDF417', 'BC_EAN8', 'BC_EAN13', 'BC_CODE39', 'BC_CODE93', 'BC_CODE49', 'BC_CODE128', 'BC_CODABAR', 'BC_GS1_128' ]; for (let i = 0; i < types.length; i++) { sheet.setFormula(i + 3, 3, '=' + types[i] + '(C' + (i + 4) + ')'); // change color and backgroudColor sheet.setFormula(i + 3, 4, '=' + types[i] + '(C' + (i + 4) + ',"#fff","#000")'); } for (let i = 3; i < types.length; i++) { // change showLabel sheet.setFormula(i + 3, 5, '=' + types[i] + '(C' + (i + 4) + ',,,0)'); // change labelPosition sheet.setFormula(i + 3, 6, '=' + types[i] + '(C' + (i + 4) + ',,,,"top")'); } spread.resumePaint(); } let _setData = function(sheet) { let headers = [['Default', 'Change color and backgroudColor', 'Change showLabel', 'Change labelPosition']]; let dataArray = [ ['QR code', 'Policy:411'], ['Data Matrix', 'Policy:411'], ['PDF417', 6935205311092], ['EAN-8', 4137962], ['EAN-13', 6920312296219], ['Code39', 3934712708295], ['Code93', 6945091701532], ['Code49', 6901668002433], ['Code128', 465465145645], ['Codabar', 9787560044231], ['gs1128', 235465143135] ]; sheet.addSpan(1, 1, 2, 1); sheet.addSpan(1, 2, 2, 1); sheet.addSpan(1, 3, 1, 4); sheet.setValue(1, 1, 'Type'); sheet.setValue(1, 2, 'Number'); sheet.setValue(1, 3, 'Barcode'); sheet.setArray(2, 3, headers); sheet.setArray(3, 1, dataArray); } let _setStyle = function(sheet) { sheet.setColumnWidth(0, 20); for (let row = 3; row < 14; row++) { sheet.setRowHeight(row, 100); } for (let col = 1; col < 7; col++) { sheet.setColumnWidth(col, 200); } sheet .getRange(1, 1, 13, 6) .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, 2, 6) .foreColor('#000') .backColor('#FFF3CE') .setBorder(new GC.Spread.Sheets.LineBorder('orange', GC.Spread.Sheets.LineStyle.thin), {all: true}); } return ( <div class="sample-tutorial"> <div class="sample-spreadsheets"> <SpreadSheets workbookInitialized={spread => initSpread(spread)}> <Worksheet autoGenerateColumns={autoGenerateColumns} /> </SpreadSheets> </div> </div> ); }
import * as React from 'react'; import * as ReactDOM from 'react-dom'; import GC from '@mescius/spread-sheets'; import '@mescius/spread-sheets-barcode'; import { SpreadSheets, Worksheet, Column } from '@mescius/spread-sheets-react'; import './styles.css'; const Component = React.Component; const GCsheets = GC.Spread.Sheets; const FORMULA = 'BC_PDF417'; function _getElementById(id) { return document.getElementById(id); } export class App extends Component { constructor(props) { super(props); this.spread = null; this.autoGenerateColumns = true; } render() { return ( <div class="sample-tutorial"> <div class="sample-spreadsheets"> <SpreadSheets workbookInitialized={spread => this.initSpread(spread)}> <Worksheet autoGenerateColumns={this.autoGenerateColumns} /> </SpreadSheets> </div> </div> ); } initSpread(spread) { this.spread = spread; spread.suspendPaint(); let sheet = spread.getSheet(0); sheet.name('customSheet'); this._setData(sheet); this._setStyle(sheet); let types = [ 'BC_QRCODE', 'BC_DataMatrix', 'BC_PDF417', 'BC_EAN8', 'BC_EAN13', 'BC_CODE39', 'BC_CODE93', 'BC_CODE49', 'BC_CODE128', 'BC_CODABAR', 'BC_GS1_128' ]; for (let i = 0; i < types.length; i++) { sheet.setFormula(i + 3, 3, '=' + types[i] + '(C' + (i + 4) + ')'); // change color and backgroudColor sheet.setFormula(i + 3, 4, '=' + types[i] + '(C' + (i + 4) + ',"#fff","#000")'); } for (let i = 3; i < types.length; i++) { // change showLabel sheet.setFormula(i + 3, 5, '=' + types[i] + '(C' + (i + 4) + ',,,0)'); // change labelPosition sheet.setFormula(i + 3, 6, '=' + types[i] + '(C' + (i + 4) + ',,,,"top")'); } spread.resumePaint(); } _setData(sheet) { let headers = [['Default', 'Change color and backgroudColor', 'Change showLabel', 'Change labelPosition']]; let dataArray = [ ['QR code', 'Policy:411'], ['Data Matrix', 'Policy:411'], ['PDF417', 6935205311092], ['EAN-8', 4137962], ['EAN-13', 6920312296219], ['Code39', 3934712708295], ['Code93', 6945091701532], ['Code49', 6901668002433], ['Code128', 465465145645], ['Codabar', 9787560044231], ['gs1128', 235465143135] ]; sheet.addSpan(1, 1, 2, 1); sheet.addSpan(1, 2, 2, 1); sheet.addSpan(1, 3, 1, 4); sheet.setValue(1, 1, 'Type'); sheet.setValue(1, 2, 'Number'); sheet.setValue(1, 3, 'Barcode'); sheet.setArray(2, 3, headers); sheet.setArray(3, 1, dataArray); } _setStyle(sheet) { sheet.setColumnWidth(0, 20); for (let row = 3; row < 14; row++) { sheet.setRowHeight(row, 100); } for (let col = 1; col < 7; col++) { sheet.setColumnWidth(col, 200); } sheet .getRange(1, 1, 13, 6) .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, 2, 6) .foreColor('#000') .backColor('#FFF3CE') .setBorder(new GC.Spread.Sheets.LineBorder('orange', GC.Spread.Sheets.LineStyle.thin), {all: true}); } }
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/en/react/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <!-- SystemJS --> <script src="$DEMOROOT$/en/react/node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('$DEMOROOT$/en/lib/react/license.js').then(function () { System.import('./src/app'); }); </script> </head> <body> <div id="app"></div> </body> </html>
.sample-tutorial { position: relative; height: 100%; overflow: hidden; } .sample-spreadsheets { width: 100%; height: 100%; overflow: hidden; float: left; } .options-container legend { text-align: center; } .option-row { font-size: 14px; padding: 5px; } input { display:block; width: 100%; margin: 8px 0; box-sizing: border-box; } label, input { padding: 4px 6px; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; } #app { height: 100%; } #drawUnderline { display: inline-block; width: 30px; } #drawUnderlineLabel { display: inline-block; } #allowAutoCreateHyperlink { display: inline-block; width: 30px; } #setHyperlinkButton { font-weight: bold; background-color: #ecf3ff; width: 200px; height: 35px; border-radius: 4px; border-color: #0b93d5; border-width: thin; }
(function (global) { System.config({ transpiler: 'plugin-babel', babelOptions: { es2015: true, react: true }, meta: { '*.css': { loader: 'css' } }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, // map tells the System loader where to look for things map: { '@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js', '@mescius/spread-sheets-barcode': 'npm:@mescius/spread-sheets-barcode/index.js', '@mescius/spread-sheets-react': 'npm:@mescius/spread-sheets-react/index.js', '@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js', 'react': 'npm:react/umd/react.production.min.js', 'react-dom': 'npm:react-dom/umd/react-dom.production.min.js', 'css': 'npm:systemjs-plugin-css/css.js', 'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js', 'systemjs-babel-build':'npm:systemjs-plugin-babel/systemjs-babel-browser.js' }, // packages tells the System loader how to load when no filename and/or no extension packages: { src: { defaultExtension: 'jsx' }, "node_modules": { defaultExtension: 'js' }, } }); })(this);