首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XpsDocument.GetFixedDocumentSequence抛出XamlParseException

XpsDocument.GetFixedDocumentSequence抛出XamlParseException
EN

Stack Overflow用户
提问于 2014-06-25 13:39:42
回答 1查看 1K关注 0票数 3

我必须将一个.xlsx文件导入到我的WPF应用程序中并查看它。我将文档转换为.xps,然后加载。在那之后,我打电话给GetFixedDocumentSequence(),在那里我得到了这个异常

XamlParseException: {"UnicodeString属性不包含与索引属性内容相对应的足够字符。“}。

这是我的代码:

代码语言:javascript
复制
private void LoadData()
{
    string xpsPath = ViewDocumentViewer("D:\\test.xlsx");
    DisplayXPSFile(xpsPath);
}

private string ViewDocumentViewer(string path)
{
    try
    {
        string xpsPath;
        var excelApp = new Microsoft.Office.Interop.Excel.Application();
        excelApp.DisplayAlerts = false;
        excelApp.Visible = false;
        Microsoft.Office.Interop.Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(path);
        xpsPath = ExportXPS(excelWorkbook, path);
        excelWorkbook.Close(false, null, null);
        excelApp.Quit();
        Marshal.ReleaseComObject(excelApp);
        excelApp = null;

        return xpsPath;
    }
    catch
    { 
    }

    return string.Empty;
}

string ExportXPS(Microsoft.Office.Interop.Excel.Workbook excelWorkbook, string path)
{
    string xpsFileName;
    xpsFileName = (new DirectoryInfo(path)).FullName;
    xpsFileName = xpsFileName.Replace(new FileInfo(path).Extension, "") + ".xps";
    excelWorkbook.ExportAsFixedFormat(XlFixedFormatType.xlTypeXPS,
    Filename: xpsFileName,
    OpenAfterPublish: false);

    return xpsFileName;
}

void DisplayXPSFile(string xpsFileName)
{
    XpsDocument xpsPackage = new XpsDocument(xpsFileName, FileAccess.Read, CompressionOption.NotCompressed);
    FixedDocumentSequence fixedDocumentSequence = xpsPackage.GetFixedDocumentSequence();
    DocView.Document = fixedDocumentSequence;
}
EN

回答 1

Stack Overflow用户

发布于 2014-09-20 16:40:17

从Excel到XPS的转换似乎有问题。这通常与字形或字体问题有关。您可以打开XPS文件(我在Visual:http://visualstudiogallery.msdn.microsoft.com/450a00e3-5a7d-4776-be2c-8aa8cec2a75b?SRC=VSIDE上使用这个扩展名)来查看问题的来源。导航到生成错误的页面,并找到包含问题的符号。

代码语言:javascript
复制
<Canvas Clip="F 1 M137.710006714,208.58001709 L476.861022949,208.58001709 L476.861022949,208.58001709 L476.861022949,219.83001709 L476.861022949,219.83001709 L137.710006714,219.83001709 Z">
    <Glyphs OriginX="0" OriginY="0" UnicodeString="D" Indices=",55.6" Fill="#FF000000" FontRenderingEmSize="1" FontUri="/Resources/076a5115-0000-0000-0000-000000000000.odttf" RenderTransform="8.949999809,0,0,8.949999809,185.458496094,218.330078125" />
</Canvas>

您还可以找到有关这个also:http://msdn.microsoft.com/en-us/library/ms748985.aspx的更多文档。

由于使用Excel生成XPS,您将几乎没有对转换过程的控制,所以我建议检查Excel文档中使用的字体。也许字体的使用有问题。

问候

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24410317

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档