20
¿Cómo puedo cambiar la familia de fuentes del documento a través de OpenXml? Intenté algunas formas, pero, cuando abro el documento, siempre está en Calibri¿Cómo puedo cambiar la fuente abierta xml
Sigue mi código y lo que probé.
La cabecera del constructor creo que es inútil para publicar
private static void BuildDocument(string fileName, List<string> lista, string tipo)
{
using (WordprocessingDocument w = WordprocessingDocument.Create(fileName, WordprocessingDocumentType.Document))
{
MainDocumentPart mp = w.AddMainDocumentPart();
DocumentFormat.OpenXml.Wordprocessing.Document d = new DocumentFormat.OpenXml.Wordprocessing.Document();
Body b = new Body();
DocumentFormat.OpenXml.Wordprocessing.Paragraph p = new DocumentFormat.OpenXml.Wordprocessing.Paragraph();
Run r = new Run();
//// Get and format the text.
for (int i = 0; i < lista.Count; i++)
{
Text t = new Text();
t.Text = lista[i];
if (t.Text == " ")
{
r.Append(new CarriageReturn());
}
else
{
r.Append(t);
r.Append(new CarriageReturn());
}
}
//// What I Tried
RunProperties rPr = new RunProperties(
new RunFonts()
{
Ascii = "Arial"
});
lista.Clear();
p.Append(r);
b.Append(p);
HeaderPart hp = mp.AddNewPart<HeaderPart>();
string headerRelationshipID = mp.GetIdOfPart(hp);
SectionProperties sectPr = new SectionProperties();
HeaderReference headerReference = new HeaderReference();
headerReference.Id = headerRelationshipID;
headerReference.Type = HeaderFooterValues.Default;
sectPr.Append(headerReference);
b.Append(sectPr);
d.Append(b);
//// Customize the header.
if (tipo == "alugar")
{
hp.Header = BuildHeader(hp, "Anúncio Aluguel de Imóvel");
}
else if (tipo == "vender")
{
hp.Header = BuildHeader(hp, "Anúncio Venda de Imóvel");
}
else
{
hp.Header = BuildHeader(hp, "Aluguel/Venda de Imóvel");
}
hp.Header.Save();
mp.Document = d;
mp.Document.Save();
w.Close();
}
}
Cuando crea documentos con caracteres que no son ASCII, necesita establecer propiedades adicionales en la instancia 'RunFonts'. Por ejemplo, si desea establecer la fuente de un texto con diéresis alemanas, debe cambiar la propiedad 'HighAnsi' a su fuente (por ejemplo," Arial ") también. – Chaquotay