wordxml-builder
Version:
Librería TypeScript para construir documentos XML compatibles con Microsoft Word
58 lines (57 loc) • 1.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.WordXMLBuilder = void 0;
const paragraph_1 = require("./paragraph");
const table_1 = require("./table");
/**
* Clase principal para construir documentos XML compatibles con Word
*/
class WordXMLBuilder {
constructor() {
this.paragraphs = [];
this.tables = [];
}
/**
* Agrega un párrafo al documento
* @param content Contenido del párrafo
* @param style Estilo del párrafo (opcional)
* @returns Instancia del párrafo creado
*/
addParagraph(content, style) {
const paragraph = new paragraph_1.Paragraph(content, style);
this.paragraphs.push(paragraph);
return paragraph;
}
/**
* Agrega una tabla al documento
* @param table Configuración de la tabla
*/
addTable(table) {
this.tables.push(table);
}
/**
* Genera el contenido XML del documento
* @returns Contenido XML del documento
*/
getContent() {
const content = [];
// Agregar párrafos
this.paragraphs.forEach((paragraph) => {
content.push(paragraph.toXML());
});
// Agregar tablas
this.tables.forEach((table) => {
const builder = new table_1.TableBuilder(table);
content.push(builder.toXML());
});
return content.join('\n');
}
/**
* Limpia el contenido del documento
*/
clear() {
this.paragraphs = [];
this.tables = [];
}
}
exports.WordXMLBuilder = WordXMLBuilder;