FWorkbookSheetsPrintMixin
| packages | @univerjs-pro/sheets-print |
|---|
APIs
closePrintDialog
Close print preview dialog.
Signature
closePrintDialog(): voidExamples
const fWorkbook = univerAPI.getActiveWorkbook()
fWorkbook.openPrintDialog()
// Close print dialog after 3 seconds
setTimeout(() => {
fWorkbook.closePrintDialog()
}, 3000)openPrintDialog
Open print preview dialog.
Signature
openPrintDialog(): voidExamples
const fWorkbook = univerAPI.getActiveWorkbook()
fWorkbook.openPrintDialog()print
Using current print config and render config to print.
Signature
print(): voidExamples
const fWorkbook = univerAPI.getActiveWorkbook()
// Update print layout config by default
fWorkbook.updatePrintConfig({})
// Update print render config by default
fWorkbook.updatePrintRenderConfig({})
// Start print
fWorkbook.print()saveScreenshotToClipboard
Save screenshot of current range to clipboard.
This API is only available with a license. Without a license, usage is restricted, and save operations will return false.
We use the Clipboard API to save the image to the clipboard, which may fail in an insecure network environment or in some unsupported browsers. A successful save will return true.
Signature
saveScreenshotToClipboard(): Promise<boolean>Returns
- (
Promise<boolean>) — - The result of saving the screenshot to the clipboard.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const result = await fWorkbook.saveScreenshotToClipboard()
console.log(result) // true or falseupdatePrintConfig
Update print config, include print area, page-setting, scale, freeze, margin, and etc.
Signature
updatePrintConfig(config: ISheetPrintLayoutConfig): FWorkbookParameters
config(ISheetPrintLayoutConfig) — - The print layout config.
Returns
- (
FWorkbook) — - The current workbook instance for chaining.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getActiveSheet()
const subUnitId = fWorksheet.getSheetId()
// Update print layout config
fWorkbook.updatePrintConfig({
area: univerAPI.Enum.PrintArea.CurrentSheet, // print current sheet
subUnitIds: [subUnitId],
paperSize: univerAPI.Enum.PrintPaperSize.A4, // A4 paper size
scale: univerAPI.Enum.PrintScale.FitPage, // fit content to page
freeze: [univerAPI.Enum.PrintFreeze.Row], // freeze row headers
margin: univerAPI.Enum.PrintPaperMargin.Normal, // normal margin
// ... other settings
})
// Start print
fWorkbook.print()updatePrintRenderConfig
Update print render config, include print header-footer setting, alignment, gridline, and etc.
Signature
updatePrintRenderConfig(config: ISheetPrintRenderConfig): FWorkbookParameters
config(ISheetPrintRenderConfig) — - The print render config.
Returns
- (
FWorkbook) — - The current workbook instance for chaining.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
// Update print layout config by default
fWorkbook.updatePrintConfig({})
// Update print render config
fWorkbook.updatePrintRenderConfig({
gridlines: true, // show gridlines
hAlign: univerAPI.Enum.PrintAlign.Middle, // horizontal align middle
vAlign: univerAPI.Enum.PrintAlign.Middle, // vertical align middle
headerFooter: [ // the array of header and footer elements to include, here is page numbers and worksheet name
univerAPI.Enum.PrintHeaderFooter.PageSize,
univerAPI.Enum.PrintHeaderFooter.WorksheetTitle,
],
// ... other settings
})
// Start print
fWorkbook.print()