Formas
Puede dibujar diagramas de flujo, anotaciones, callouts y guías visuales directamente en una hoja de trabajo con formas.
Modo de complemento
Instalación
pnpm add @univerjs-pro/engine-formula @univerjs/drawing @univerjs/drawing-ui @univerjs/sheets-drawing @univerjs/sheets-drawing-ui @univerjs-pro/sheets-shape @univerjs-pro/sheets-shape-uinpm install @univerjs-pro/engine-formula @univerjs/drawing @univerjs/drawing-ui @univerjs/sheets-drawing @univerjs/sheets-drawing-ui @univerjs-pro/sheets-shape @univerjs-pro/sheets-shape-uiyarn add @univerjs-pro/engine-formula @univerjs/drawing @univerjs/drawing-ui @univerjs/sheets-drawing @univerjs/sheets-drawing-ui @univerjs-pro/sheets-shape @univerjs-pro/sheets-shape-uibun add @univerjs-pro/engine-formula @univerjs/drawing @univerjs/drawing-ui @univerjs/sheets-drawing @univerjs/sheets-drawing-ui @univerjs-pro/sheets-shape @univerjs-pro/sheets-shape-uiLas formas también requieren UniverProFormulaEnginePlugin de @univerjs-pro/engine-formula. Reemplazar la importación y registro UniverFormulaEnginePlugin existente en su inicialización de base con este plugin. No registre ambos motores de fórmula, porque insertar una forma puede de otra manera fallar con un error de dependencia perdido.
Los plugins de forma dependen de los plugins de dibujo, así que regístrese UniverDrawingPlugin, UniverSheetsDrawingPlugin, UniverDrawingUIPlugin, y UniverSheetsDrawingUIPlugin antes de registrar los plugins.
Uso
import { UniverProFormulaEnginePlugin } from '@univerjs-pro/engine-formula'import { UniverSheetsShapePlugin } from '@univerjs-pro/sheets-shape'import { UniverSheetsShapeUIPlugin } from '@univerjs-pro/sheets-shape-ui'import SheetsShapeUIEnUS from '@univerjs-pro/sheets-shape-ui/locale/en-US'import { LocaleType, mergeLocales, Univer } from '@univerjs/core'import { UniverDrawingPlugin } from '@univerjs/drawing'import { UniverDrawingUIPlugin } from '@univerjs/drawing-ui'import DrawingUIEnUS from '@univerjs/drawing-ui/locale/en-US'import { UniverSheetsDrawingPlugin } from '@univerjs/sheets-drawing'import { UniverSheetsDrawingUIPlugin } from '@univerjs/sheets-drawing-ui'import SheetsDrawingUIEnUS from '@univerjs/sheets-drawing-ui/locale/en-US'import '@univerjs-pro/sheets-shape/facade'import '@univerjs/drawing-ui/lib/index.css'import '@univerjs/sheets-drawing-ui/lib/index.css'import '@univerjs-pro/sheets-shape-ui/lib/index.css'const univer = new Univer({ locale: LocaleType.EN_US, locales: { [LocaleType.EN_US]: mergeLocales( DrawingUIEnUS, SheetsDrawingUIEnUS, SheetsShapeUIEnUS, ), },})univer.registerPlugin(UniverProFormulaEnginePlugin)univer.registerPlugin(UniverDrawingPlugin)univer.registerPlugin(UniverDrawingUIPlugin)univer.registerPlugin(UniverSheetsDrawingPlugin)univer.registerPlugin(UniverSheetsDrawingUIPlugin)univer.registerPlugin(UniverSheetsShapePlugin)univer.registerPlugin(UniverSheetsShapeUIPlugin)Si tiene una licencia comercial Univer, consulte Utilizando Licencia en Cliente para la configuración del cliente.
Compatibilidad móvil
Configurar el editor móvil primero. En la configuración de modo plugin en esta página, sustitúyase los registros de escritorio enumerados a continuación con las exportaciones móviles de los mismos paquetes, y complete el reemplazo antes de abrir un documento. Los plugins modelo, estilos, locales y las importaciones Facade siguen sin cambiar. No registre ambas variantes.
| Paquete | Registro de escritorio | Registro móvil |
|---|---|---|
@univerjs/drawing-ui | UniverDrawingUIPlugin | UniverDrawingMobileUIPlugin |
@univerjs/sheets-drawing-ui | UniverSheetsDrawingUIPlugin | UniverSheetsDrawingMobileUIPlugin |
@univerjs-pro/sheets-shape-ui | UniverSheetsShapeUIPlugin | UniverSheetsShapeMobileUIPlugin |
Modo preestablecido
Las formas se incluyen en el preset @univerjs/preset-sheets-advanced. Ese preset ya registra UniverProFormulaEnginePlugin, por lo que el motor de fórmula no necesita ser reemplazado manualmente.
Instalación
UniverSheetsAdvancedPreset de @univerjs/preset-sheets-advanced requiere el preset UniverSheetsDrawingPreset en tiempo de ejecución, así que instale @univerjs/preset-sheets-drawing primero.
pnpm add @univerjs/preset-sheets-drawing @univerjs/preset-sheets-advancednpm install @univerjs/preset-sheets-drawing @univerjs/preset-sheets-advancedyarn add @univerjs/preset-sheets-drawing @univerjs/preset-sheets-advancedbun add @univerjs/preset-sheets-drawing @univerjs/preset-sheets-advancedUso
import { UniverSheetsAdvancedPreset } from '@univerjs/preset-sheets-advanced'import UniverPresetSheetsAdvancedEnUS from '@univerjs/preset-sheets-advanced/locales/en-US'import { UniverSheetsCorePreset } from '@univerjs/preset-sheets-core'import UniverPresetSheetsCoreEnUS from '@univerjs/preset-sheets-core/locales/en-US'import { UniverSheetsDrawingPreset } from '@univerjs/preset-sheets-drawing'import UniverPresetSheetsDrawingEnUS from '@univerjs/preset-sheets-drawing/locales/en-US'import { createUniver, LocaleType, mergeLocales } from '@univerjs/presets'import '@univerjs/preset-sheets-core/lib/index.css'import '@univerjs/preset-sheets-drawing/lib/index.css'import '@univerjs/preset-sheets-advanced/lib/index.css'const { univerAPI } = createUniver({ locale: LocaleType.EN_US, locales: { [LocaleType.EN_US]: mergeLocales( UniverPresetSheetsCoreEnUS, UniverPresetSheetsDrawingEnUS, UniverPresetSheetsAdvancedEnUS, ), }, presets: [ UniverSheetsCorePreset(), UniverSheetsDrawingPreset(), UniverSheetsAdvancedPreset(), ],})Si tiene una licencia comercial Univer, consulte Utilizando Licencia en Cliente para la configuración del cliente.
API de Facade
Las definiciones completas del tipo Facade API están en FacadeAPI.
Importar
Plugin mode note
Sólo el modo complemento requiere importar manualmente el paquete Facade. El modo Preestablecido ya incluye el paquete Fachada correspondiente, por lo que no se necesita ninguna importación adicional.
import '@univerjs-pro/sheets-shape/facade'Insertar formas básicas
Pase los datos de creación de forma estándar a FWorksheet.insertShape, que devuelve un mango de fachada en vivo.
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()const rectShape = fWorksheet.insertShape({ shapeType: univerAPI.Enum.ShapeTypeEnum.Rect, transform: { left: 120, top: 80, width: 240, height: 120 }, shapeData: { fill: { fillType: univerAPI.Enum.ShapeFillEnum.SolidFill, color: '#e6f4ff', }, stroke: { lineStrokeType: univerAPI.Enum.ShapeLineTypeEnum.SolidLine, color: '#1677ff', width: 2, }, },})if (!rectShape) throw new Error('Shape could not be inserted.')Editar el texto de una forma
El ejemplo a continuación continúa de una forma que insertShape() devolvió, ya sea la forma creada en el ejemplo anterior o la forma utilizada en el fragmento a continuación. getText() vuelve un mango FShapeText vivo: getPlainText() lee el texto, setText() reemplaza todo, y los métodos de fuente, color y alineación aplican formato.
if (!rectShape) throw new Error('Shape is not available')const shapeText = rectShape.getText()console.log(shapeText.getPlainText())shapeText .setText('Quarterly review') .setFontSize(18) .setColor('#2563eb') .setBold(true) .setHorizontalAlign(univerAPI.Enum.HorizontalAlign.CENTER) .setVerticalAlign(univerAPI.Enum.VerticalAlign.MIDDLE)setText() reemplaza el texto existente; utiliza setRichText() cuando una forma necesita varios estilos. Para editar texto rico existente, llame a getRichText()?.copy(), modifique el constructor, luego pasar a setRichText(). Ese constructor es una copia desprendida, por lo que los cambios a él no se aplican automáticamente. Véase estilo de texto y texto caja de relleno y diseño para las otras opciones.
const richText = univerAPI.newRichText() .text('Quarterly ') .bold('review')shapeText.setRichText(richText)Inserte y conecte formas de conector
Cree un conector con FWorksheet.insertShape, y luego ata ambos extremos a través de la fachada FConnectorShape devuelta.
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()const leftShape = fWorksheet.insertShape({ shapeType: univerAPI.Enum.ShapeTypeEnum.RoundRect, transform: { left: 80, top: 80, width: 180, height: 100 },})const rightShape = fWorksheet.insertShape({ shapeType: univerAPI.Enum.ShapeTypeEnum.Ellipse, transform: { left: 420, top: 200, width: 180, height: 100 },})const connectorShape = fWorksheet.insertShape({ shapeType: univerAPI.Enum.ShapeTypeEnum.BentConnector3, transform: { left: 240, top: 130, width: 240, height: 120 },})if (!leftShape || !rightShape || !connectorShape) { throw new Error('Shapes could not be inserted.')}const startSite = leftShape.getConnectionSites()[0]const rightSites = rightShape.getConnectionSites()const endSite = rightSites[2] ?? rightSites[0]if (!startSite || !endSite) throw new Error('Connection site not found.')connectorShape .bindStart(leftShape.getId(), startSite.index) .bindEnd(rightShape.getId(), endSite.index) .setEndArrow(univerAPI.Enum.ShapeArrowTypeEnum.Arrow)Actualizar y eliminar formas
Actualizar y eliminar una forma ambos operan a través de su mango de fachada en vivo.
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()const firstShape = fWorksheet.getShapes().find(shape => !shape.isConnectorShape())if (firstShape) { firstShape .setStrokeColor('#ff4d4f') .setStrokeWidth(3) .setSolidFill('#fff1f0') // Remove the shape later if needed const removed = firstShape.remove() console.log(removed)}Copiar formato de formas
Seleccione una forma de origen, gire en el pintor de formato, luego seleccione la forma de destino. El pintor copia llena, trazo, efectos, y el formato de texto que soporta, mientras que el objetivo mantiene su identidad, geometría, contenido de texto y unión de fórmulas. Eliminar el formato restaura los defectos aplicados en la inserción. SmartArt no participa en esta operación. El plugin de forma UI registra este comportamiento.
¿Cómo es esta guía?