private static void UpdateFontSettings(WordprocessingDocument content, WordprocessingDocument template)
{
if (content != null && content.MainDocumentPart != null && content.MainDocumentPart.FontTablePart != null &&
template != null && template.MainDocumentPart != null && template.MainDocumentPart.FontTablePart != null)
{
IEnumerable<OpenXmlPart> partsToDelete = from idPartPair in content.MainDocumentPart.FontTablePart.Parts
select idPartPair.OpenXmlPart;
content.MainDocumentPart.FontTablePart.DeleteParts(partsToDelete);
StreamReader streamReader = null;
StreamWriter streamWriter = null;
try
{
streamReader = new StreamReader(template.MainDocumentPart.FontTablePart.GetStream());
streamWriter = n开发者_运维问答ew StreamWriter(content.MainDocumentPart.FontTablePart.GetStream(FileMode.Create));
}
catch
{
if (streamReader != null)
{
streamReader.Close();
}
throw;
}
using (streamWriter)
{
streamWriter.Write(streamReader.ReadToEnd());
}
if (streamReader != null)
{
streamReader.Close();
}
}
}
I would suggest setting your encoding type when you create your StreamWriter
. I believe it defaults to ANSI for most systems, though you might require UTF8 or something else.
精彩评论