To use the document properties, follow this example:
You can directly modify the core and application properties of the document. The supported attributes are as follows:
You can manipulate the custom properties of a document by using the Custom Property Manager. For example:
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 GC from '@mescius/spread-sheets';
import '@mescius/spread-sheets-io';
import { SpreadSheets, Worksheet } from '@mescius/spread-sheets-react';
import { sheetJSON } from './utils';
import './styles.css';
window.GC = GC;
function getFileType (file) {
if (!file) { return; }
var fileName = file.name;
var extensionName = fileName.substring(fileName.lastIndexOf(".") + 1);
if (extensionName === 'xlsx' || extensionName === 'xlsm') {
return 'xlsx';
}
}
export function AppFunc() {
const [spread, setSpread] = React.useState(null);
const [selectedFile, setSelectedFile] = React.useState(null);
function initSpread(spread) {
setSpread(spread);
}
function open() {
const file = selectedFile;
if (!file) { return; }
const fileType = getFileType(file);
if (fileType === 'xlsx') {
spread.import(file, () => {
initProductInformationSheet(spread);
});
}
}
function initProductInformationSheet(spread) {
const docProps = spread.docProps;
spread.suspendPaint();
if (docProps) {
const newSheet = new GC.Spread.Sheets.Worksheet('Product Information');
newSheet.fromJSON(sheetJSON);
spread.addSheet(0, newSheet);
spread.setActiveSheetIndex(0);
const sheet = spread.getActiveSheet();
// set document properties
sheet.setValue(1, 1, docProps.coreDocProps && docProps.coreDocProps.title);
sheet.setValue(2, 1, docProps.coreDocProps && docProps.coreDocProps.subject);
sheet.setValue(3, 1, docProps.coreDocProps && docProps.coreDocProps.creator);
sheet.setValue(4, 1, docProps.coreDocProps && docProps.coreDocProps.keywords);
sheet.setValue(5, 1, docProps.coreDocProps && docProps.coreDocProps.description);
sheet.setValue(6, 1, docProps.coreDocProps && docProps.coreDocProps.category);
sheet.setValue(7, 1, docProps.coreDocProps && docProps.coreDocProps.contentStatus);
sheet.setValue(1, 3, docProps.appDocProps && docProps.appDocProps.manager);
sheet.setValue(2, 3, docProps.appDocProps && docProps.appDocProps.company);
sheet.setValue(3, 3, docProps.appDocProps && docProps.appDocProps.hyperlinkBase);
const customDocPropsManager = docProps.customDocPropsManager;
if (customDocPropsManager && customDocPropsManager.all()) {
customDocPropsManager.all().forEach((prop, index) => {
sheet.setValue(index + 1, 4, prop.name);
sheet.setValue(index + 1, 5, prop.value);
});
}
}
spread.resumePaint();
};
function save() {
const sheetIndex = spread.getSheetIndex('Product Information');
if (typeof sheetIndex === 'number' && sheetIndex >= 0) {
spread.removeSheet(sheetIndex);
}
const fileName = 'export.xlsx';
const fileType = GC.Spread.Sheets.FileType.excel;
spread.export(function(blob) { saveAs(blob, fileName); }, function() {}, { fileType });
}
function onSelectedFileChange(e) {
let selectedFile = e.target.files[0];
setSelectedFile(selectedFile);
}
return <div class="sample-tutorial">
<div class="sample-container">
<div class="sample-spreadsheets">
<SpreadSheets workbookInitialized={spread => initSpread(spread)}>
<Worksheet>
</Worksheet>
</SpreadSheets>
</div>
</div>
<div class="options-container">
<div class="option-row">
<div class="inputContainer">
<input id="selectedFile" type="file" accept=".xlsx, .xlsm" onChange={onSelectedFileChange} />
<button class="settingButton" id="open" onClick={open}>Open</button>
</div>
<div class="inputContainer export-input-container">
<div class="label">Export to Excel: </div>
<div class="space"></div>
<button class="settingButton" id="save" onClick={save}>Save</button>
</div>
</div>
</div>
</div>;
}
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { SpreadSheets, Worksheet } from '@mescius/spread-sheets-react';
import '@mescius/spread-sheets-io';
import './styles.css';
const Component = React.Component;
window.GC = GC;
function getFileType (file) {
if (!file) { return; }
var fileName = file.name;
var extensionName = fileName.substring(fileName.lastIndexOf(".") + 1);
if (extensionName === 'xlsx' || extensionName === 'xlsm') {
return 'xlsx';
}
}
export class App extends Component {
constructor(props) {
super(props);
this.spread = null;
this.state = { selectedFile: null };
this.open = this.open.bind(this);
this.save = this.save.bind(this);
this.onSelectedFileChange = this.onSelectedFileChange.bind(this);
}
render() {
return <div class="sample-tutorial">
<div class="sample-container">
<div class="sample-spreadsheets">
<SpreadSheets workbookInitialized={spread => this.initSpread(spread)}>
<Worksheet>
</Worksheet>
</SpreadSheets>
</div>
</div>
<div class="options-container">
<div class="option-row">
<div class="inputContainer">
<input id="selectedFile" type="file" accept=".xlsx, .xlsm" onChange={this.onSelectedFileChange} />
<button class="settingButton" id="open" onClick={this.open}>Open</button>
</div>
<div class="inputContainer export-input-container">
<div class="label">Export to Excel: </div>
<div class="space"></div>
<button class="settingButton" id="save" onClick={this.save}>Save</button>
</div>
</div>
</div>
</div>;
}
initSpread(spread) {
this.spread = spread;
}
async open() {
const file = this.state.selectedFile;
if (!file) { return; }
const fileType = getFileType(file);
if (fileType === 'xlsx') {
this.spread.import(file, () => {
this.initProductInformationSheet();
});
}
}
initProductInformationSheet() {
const docProps = this.spread.docProps;
this.spread.suspendPaint();
if (docProps) {
const newSheet = new GC.Spread.Sheets.Worksheet('Product Information');
newSheet.fromJSON(sheetJSON);
this.spread.addSheet(0, newSheet);
this.spread.setActiveSheetIndex(0);
const sheet = this.spread.getActiveSheet();
// set document properties
sheet.setValue(1, 1, docProps.coreDocProps && docProps.coreDocProps.title);
sheet.setValue(2, 1, docProps.coreDocProps && docProps.coreDocProps.subject);
sheet.setValue(3, 1, docProps.coreDocProps && docProps.coreDocProps.creator);
sheet.setValue(4, 1, docProps.coreDocProps && docProps.coreDocProps.keywords);
sheet.setValue(5, 1, docProps.coreDocProps && docProps.coreDocProps.description);
sheet.setValue(6, 1, docProps.coreDocProps && docProps.coreDocProps.category);
sheet.setValue(7, 1, docProps.coreDocProps && docProps.coreDocProps.contentStatus);
sheet.setValue(1, 3, docProps.appDocProps && docProps.appDocProps.manager);
sheet.setValue(2, 3, docProps.appDocProps && docProps.appDocProps.company);
sheet.setValue(3, 3, docProps.appDocProps && docProps.appDocProps.hyperlinkBase);
const customDocPropsManager = docProps.customDocPropsManager;
if (customDocPropsManager && customDocPropsManager.all()) {
customDocPropsManager.all().forEach((prop, index) => {
sheet.setValue(index + 1, 4, prop.name);
sheet.setValue(index + 1, 5, prop.value);
});
}
}
this.spread.resumePaint();
};
save() {
const sheetIndex = spread.getSheetIndex('Product Information');
if (typeof sheetIndex === 'number' && sheetIndex >= 0) {
spread.removeSheet(sheetIndex);
}
const fileName = 'export.xlsx';
const fileType = GC.Spread.Sheets.FileType.excel;
spread.export(function(blob) { saveAs(blob, fileName); }, function() {}, { fileType });
}
onSelectedFileChange(e) {
const selectedFile = e.target.files[0];
this.setState({ selectedFile });
}
}
ReactDOM.render(<App />, _getElementById('app'));
<!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">
<script src="$DEMOROOT$/spread/source/js/FileSaver.js" type="text/javascript"></script>
<!-- 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>
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
#app {
height: 100%;
}
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
.sample-container {
width: calc(100% - 280px);
height: 100%;
float: left;
}
.sample-spreadsheets {
width: 100%;
height: 100%;
overflow: hidden;
}
.options-container {
float: right;
width: 280px;
height: 100%;
box-sizing: border-box;
background: #fbfbfb;
overflow: auto;
}
.sample-options {
z-index: 1000;
}
.inputContainer {
width: 100%;
height: auto;
border: 1px solid #eee;
padding: 6px 12px;
margin-bottom: 10px;
box-sizing: border-box;
}
.export-input-container {
display: flex;
justify-content: space-around;
align-items: center;
}
.settingButton {
color: #fff;
background: #82bc00;
outline: 0;
line-height: 1.5715;
position: relative;
display: inline-block;
font-weight: 400;
white-space: nowrap;
text-align: center;
height: 32px;
padding: 4px 15px;
font-size: 14px;
border-radius: 2px;
user-select: none;
cursor: pointer;
border: 1px solid #82bc00;
box-sizing: border-box;
margin-bottom: 10px;
margin-top: 10px;
}
.settingButton:hover {
color: #fff;
border-color: #88b031;
background: #88b031;
}
.options-title {
font-weight: bold;
margin: 4px 2px;
}
#selectedFile {
width: 180px;
}
.space {
width: 66px;
height: 31px;
display: inline-block;
}
.open-options .item {
margin: 5px 0px;
display: flex;
}
.save-options .item {
margin: 5px 0px;
display: flex;
}
.inputContainer .label {
margin-left: 3px;
display: inline-block;
}
select, input[type="text"], input[type="number"] {
display: inline-block;
margin-left: auto;
width: 120px;
font-weight: 400;
outline: 0;
line-height: 1.5715;
border-radius: 2px;
border: 1px solid #F4F8EB;
box-sizing: border-box;
}
(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-print': 'npm:@mescius/spread-sheets-print/index.js',
'@mescius/spread-sheets-react': 'npm:@mescius/spread-sheets-react/index.js',
'@mescius/spread-sheets-io': 'npm:@mescius/spread-sheets-io/index.js',
'@mescius/spread-sheets-charts': 'npm:@mescius/spread-sheets-charts/index.js',
'@mescius/spread-sheets-shapes': 'npm:@mescius/spread-sheets-shapes/index.js',
'@mescius/spread-sheets-slicers': 'npm:@mescius/spread-sheets-slicers/index.js',
'@mescius/spread-sheets-pivot-addon': 'npm:@mescius/spread-sheets-pivot-addon/index.js',
'@mescius/spread-sheets-reportsheet-addon': 'npm:@mescius/spread-sheets-reportsheet-addon/index.js',
'@mescius/spread-sheets-tablesheet': 'npm:@mescius/spread-sheets-tablesheet/index.js',
'@mescius/spread-sheets-ganttsheet': 'npm:@mescius/spread-sheets-ganttsheet/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);