Skip to content

Commit

Permalink
change: excel增加beforeTransformData钩子函数、pdf支持requestOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
501351981 committed Feb 27, 2024
1 parent 07f7966 commit afea009
Show file tree
Hide file tree
Showing 50 changed files with 719 additions and 27 deletions.
2 changes: 1 addition & 1 deletion core/packages/js-excel/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@js-preview/excel",
"type" :"module",
"version": "1.6.2",
"version": "1.6.3",
"description": "",
"main": "lib/index.js",
"files": [
Expand Down
3 changes: 3 additions & 0 deletions core/packages/js-excel/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ class JsExcelPreview {
if (!workbook._worksheets || workbook._worksheets.length === 0) {
throw new Error('未获取到数据,可能文件格式不正确或文件已损坏');
}
if(this.options.beforeTransformData && typeof this.options.beforeTransformData === 'function' ){
workbook = this.options.beforeTransformData(workbook);
}
let {workbookData, medias, workbookSource} = transferExcelToSpreadSheet(workbook, this.options);
if(this.options.transformData && typeof this.options.transformData === 'function' ){
workbookData = this.options.transformData(workbookData);
Expand Down
2 changes: 1 addition & 1 deletion core/packages/js-pdf/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@js-preview/pdf",
"type" :"module",
"version": "1.6.2",
"version": "1.6.3",
"description": "",
"main": "lib/index.js",
"files": [
Expand Down
2 changes: 2 additions & 0 deletions core/packages/js-pdf/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class JsPdfPreview{
getDocument(src){
const loadingTask = window.pdfjsLib.getDocument({
url: getUrl(src),
httpHeaders: this.requestOptions && this.requestOptions.headers,
withCredentials: this.requestOptions && this.requestOptions.withCredentials,
cMapUrl: `${this.options.staticFileUrl.endsWith('/') ? this.options.staticFileUrl : this.options.staticFileUrl + '/'}cmaps/`,
cMapPacked: true,
enableXfa: true,
Expand Down
2 changes: 1 addition & 1 deletion core/packages/vue-excel/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vue-office/excel",
"version": "1.6.1",
"version": "1.6.3",
"description": "",
"main": "lib/index.js",
"files": [
Expand Down
3 changes: 3 additions & 0 deletions core/packages/vue-excel/src/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export default defineComponent({
if (!workbook._worksheets || workbook._worksheets.length === 0) {
throw new Error('未获取到数据,可能文件格式不正确或文件已损坏');
}
if(props.options.beforeTransformData && typeof props.options.beforeTransformData === 'function' ){
workbook = props.options.beforeTransformData(workbook);
}
let {workbookData, medias, workbookSource} = transferExcelToSpreadSheet(workbook, {...defaultOptions, ...props.options});
if(props.options.transformData && typeof props.options.transformData === 'function' ){
workbookData = props.options.transformData(workbookData);
Expand Down
2 changes: 1 addition & 1 deletion core/packages/vue-pdf/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vue-office/pdf",
"version": "1.6.2",
"version": "1.6.3",
"description": "",
"main": "lib/index.js",
"files": [
Expand Down
2 changes: 2 additions & 0 deletions core/packages/vue-pdf/src/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export default defineComponent({
}
loadingTask = window.pdfjsLib.getDocument({
url: getUrl(props.src),
httpHeaders: props.requestOptions && props.requestOptions.headers,
withCredentials: props.requestOptions && props.requestOptions.withCredentials,
cMapUrl: `${props.staticFileUrl.endsWith('/') ? props.staticFileUrl : props.staticFileUrl + '/'}cmaps/`,
cMapPacked: true,
enableXfa: true,
Expand Down
6 changes: 6 additions & 0 deletions core/src/components/DocxDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ const defaultSrc = location.origin +
+ 'static/test-files/test.docx';
const docxRef = ref();
const requestOptions = {
headers: {
'component-name': 'VueOfficeDocx'
}
};
// setTimeout(()=>{
// console.log( docxRef.value.download());
Expand All @@ -32,6 +37,7 @@ const docxRef = ref();
<VueOfficeDocx
ref="docxRef"
:src="slotProps.src"
:request-options="requestOptions"
style="flex: 1;height: 0"
@rendered="onRendered"
@error="onError"
Expand Down
7 changes: 6 additions & 1 deletion core/src/components/ExcelDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ function onError(e){
useLoading.hideLoading();
}
function beforeTransformData(data){
console.log('beforeTransformData', data);
return data;
}
function transformData(data){
console.log('transformData', data);
return data;
Expand All @@ -37,7 +42,7 @@ const docxRef = ref();
<VueOfficeExcel
ref="docxRef"
:src="slotProps.src"
:options="{transformData}"
:options="{beforeTransformData, transformData}"
style="flex: 1;height: 0"
v-loading="true"
@rendered="onRendered"
Expand Down
7 changes: 7 additions & 0 deletions core/src/components/PdfDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ const defaultSrc = location.origin +
const docxRef = ref();
window.docxRef = docxRef;
const requestOptions = {
headers: {
'component-name': 'VueOfficePdf'
}
};
// setTimeout(()=>{
// console.log( docxRef.value.download());
// }, 2000);
Expand All @@ -33,6 +39,7 @@ window.docxRef = docxRef;
:src="slotProps.src"
style="flex: 1;height: 0"
:options="{lazy:true}"
:request-options="requestOptions"
@rendered="onRendered"
@error="onError"
>
Expand Down
11 changes: 9 additions & 2 deletions docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,23 @@ widthOffset:在默认渲染的列表宽度上再加 Npx宽

heightOffset:在默认渲染的列表高度上再加 Npx高

transformData:在预览之前可以通过transformData对即将渲染数据及样式进行修改
beforeTransformData: 底层通过exceljs获取excel文件内容,通过该钩子函数,可以对获取的excel文件内容进行修改,比如某个单元格的数据显示不正确,可以在此自行修改每个单元格的value值。


transformData:将获取到的excel数据进行处理之后且渲染到页面之前,可通过transformData对即将渲染的数据及样式进行修改,此时每个单元格的text值就是即将渲染到页面上的内容。

```javascript
{
"minColLength": 20,
"minRowLength": 100,
"widthOffset": 10, //在默认渲染的列表宽度上再加10px宽
"heightOffset": 10, //在默认渲染的列表高度上再加10px高
"beforeTransformData": function (workbookData){
//修改workbookData,可以打印出来看看数据格式
return workbookData;
},
"transformData": function (workbookData){
//修改workbookData
//修改workbookData,可以打印出来看看数据格式
return workbookData;
}
}
Expand Down
1 change: 1 addition & 0 deletions examples/dist/assets/DocxDemo-8c364088.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/dist/assets/DocxDemo-9ea79e80.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/dist/assets/DocxDemo-dd2985dd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/dist/assets/ExcelDemo-291862f2.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/dist/assets/ExcelDemo-426f8ab1.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/dist/assets/JsDocxDemo-0aff0a60.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit afea009

Please sign in to comment.