vue2利用LoDOP,套打技术原理调试 ●定位 ●表格多数据分页 ●循环表头、表尾 ●表体合计行,同时套打技术的循环表头各个操作的预览效果显示在富文本编辑器CKEditor中,请给出具体的代码
时间: 2024-03-27 11:34:56 浏览: 60
以下是一个参考代码,其中包含了LoDOP的初始化、设置打印数据、生成表格、循环表头、表格分页、表体合计行等操作,并将预览效果在CKEditor中显示:
```
<template>
<div>
<ckeditor
:editor="editor"
v-model="content"
:config="{
extraPlugins: 'autogrow',
autoGrow_minHeight: 200,
autoGrow_onStartup: true,
removePlugins: 'resize'
}"
/>
<button @click="preview">预览</button>
</div>
</template>
<script>
import ClassicEditor from '@ckeditor/ckeditor5-build-classic'
export default {
data () {
return {
editor: ClassicEditor,
content: '',
LODOP: null
}
},
mounted () {
const LODOP = getLodop()
if (!LODOP) {
return
}
LODOP.PRINT_INIT('打印控件初始化')
this.LODOP = LODOP
},
methods: {
preview () {
this.LODOP.NewPage()
this.LODOP.ADD_PRINT_TABLE(20, 20, 600, 200, '表格1')
this.LODOP.SET_PRINT_STYLEA(0, 'ItemType', 1)
this.LODOP.SET_PRINT_STYLEA(0, 'RepeatHeader', '1')
this.LODOP.SET_PRINT_STYLEA(0, 'RepeatFooter', '1')
const data = [
{ name: '张三', age: 20, gender: '男' },
{ name: '李四', age: 22, gender: '女' },
{ name: '王五', age: 25, gender: '男' },
{ name: '赵六', age: 28, gender: '女' }
]
const header = ['姓名', '年龄', '性别']
const footer = ['合计', 95, '']
this.generateTable(data, header, footer)
this.content = this.LODOP.GET_PREVIEW_HTML()
},
generateTable (data, header, footer) {
const columnCount = header.length
const rowHeight = 30
const rowCountPerPage = 10
const rowCount = data.length
const pageCount = Math.ceil(rowCount / rowCountPerPage)
let rowIndex = 0
let pageIndex = 1
let totalAge = 0
for (let i = 0; i < pageCount; i++) {
if (i > 0) {
this.LODOP.NewPage()
}
this.LODOP.SET_PRINT_PAGESIZE(1, 0, 0, 'A4')
this.LODOP.SET_SHOW_MODE('HIDE_PBUTTIN_PREVIEW', true)
this.LODOP.ADD_PRINT_TEXT(0, 0, 150, 25, `第${pageIndex}页`)
this.LODOP.SET_PRINT_STYLEA(0, 'Alignment', 3)
this.LODOP.ADD_PRINT_TEXT(0, 150, 150, 25, `共${pageCount}页`)
this.LODOP.SET_PRINT_STYLEA(0, 'Alignment', 1)
this.LODOP.ADD_PRINT_TEXT(0, 300, 150, 25, '表格标题')
this.LODOP.SET_PRINT_STYLEA(0, 'FontSize', 18)
this.LODOP.SET_PRINT_STYLEA(0, 'Bold', 1)
this.LODOP.SET_PRINT_STYLEA(0, 'Alignment', 2)
const table = this.LODOP.ADD_PRINT_TABLE(30, 20, 560, 0, '表格1')
this.LODOP.SET_PRINT_STYLEA(table, 'RepeatHeader', '1')
this.LODOP.SET_PRINT_STYLEA(table, 'RepeatFooter', '1')
this.LODOP.SET_PRINT_STYLEA(table, 'ItemType', 1)
this.LODOP.SET_PRINT_STYLEA(table, 'PageGroup', 'newgroup1')
this.LODOP.SET_PRINT_STYLEA(table, 'Style', 'border:1px solid #000')
const headerRow = this.LODOP.ADD_PRINT_ROW(0, rowHeight)
for (let j = 0; j < columnCount; j++) {
this.LODOP.ADD_PRINT_TEXT(headerRow, j * rowHeight, rowHeight, rowHeight, header[j])
this.LODOP.SET_PRINT_STYLEA(0, 'Alignment', 2)
}
for (let j = 0; j < rowCountPerPage; j++) {
const rowData = data[rowIndex]
const row = this.LODOP.ADD_PRINT_ROW(0, rowHeight)
this.LODOP.ADD_PRINT_TEXT(row, 0, rowHeight, rowHeight, rowData.name)
this.LODOP.ADD_PRINT_TEXT(row, rowHeight, rowHeight, rowHeight, rowData.age)
this.LODOP.ADD_PRINT_TEXT(row, rowHeight * 2, rowHeight, rowHeight, rowData.gender)
totalAge += rowData.age
rowIndex++
if (rowIndex >= rowCount) {
break
}
}
const footerRow = this.LODOP.ADD_PRINT_ROW(0, rowHeight)
for (let j = 0; j < columnCount; j++) {
if (j === 1) {
this.LODOP.ADD_PRINT_TEXT(footerRow, j * rowHeight, rowHeight, rowHeight, totalAge)
} else {
this.LODOP.ADD_PRINT_TEXT(footerRow, j * rowHeight, rowHeight, rowHeight, footer[j])
}
this.LODOP.SET_PRINT_STYLEA(0, 'Alignment', 2)
}
pageIndex++
}
}
}
}
</script>
```
在以上代码中,generateTable方法实现了表格分页、循环表头、表体合计行等功能,最终将预览效果的HTML代码通过GET_PREVIEW_HTML方法获取并赋值给content变量,显示在CKEditor中。
阅读全文