使用c#在excel中嵌入word文件并打开xml [英] Embed word file in excel using c# and open xml

查看:107
本文介绍了使用c#在excel中嵌入word文件并打开xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应该嵌入excel文件的word文件。我可以放一个word文件,但它只在excel压缩文件中显示为.bin文件。如何在excel中显示它(让我们说位置单元格C3)?我还需要稍后编辑嵌入的word文件。 Interop不是一个答案,因为这个项目应该在服务器机器上工作。谢谢。到目前为止我尝试过这样的事情。



I have a word file that should be embedded in excel file. I can put a word file, but it only shows as .bin file inside excel zipped file. How can I make it visible inside excel (let's say at position cell C3)? I also need to edit that embeded word file later. Interop is not an answer, because this project should work on a server machine. Thank you. So far i tried something like this.

public static void addWordFile(string fileName, string tableDoc)
{
    using (SpreadsheetDocument  document = SpreadsheetDocument.Open(fileName, true))
    {

        WorkbookPart wbPart = document.WorkbookPart;


        // Find the sheet with the supplied name, and then use that 
        // Sheet object to retrieve a reference to the first worksheet.
        Sheet theSheet = wbPart.Workbook.Descendants<Sheet>().
          Where(s => s.Name == "Test4").FirstOrDefault();

        // Throw an exception if there is no sheet.
        if (theSheet == null)
        {
            throw new ArgumentException("sheetName");
        }

        // Retrieve a reference to the worksheet part.
        WorksheetPart wsPart =
            (WorksheetPart)(wbPart.GetPartById(theSheet.Id));



        EmbeddedPackagePart newEmbeddedPackagePart = wsPart.AddNewPart<EmbeddedPackagePart>(@"application/vnd.openxmlformats-officedocument.wordprocessingml.document", "rId100");
        newEmbeddedPackagePart.FeedData(File.Open(@tableDoc, FileMode.Open));
      

    }
}

推荐答案

没关系,我停下来搜索这个,即使我弄清楚如何,每次嵌入文件更新时我都必须为文件生成屏幕截图,因为文件的视图实际上只是一个图像。无论如何,谢谢你。
Nevermind, I stoped searching for this, even if I foind out how, I have to generate screenshot for a file everytime embeded file get updated because the view of the file is actually just an image. Thank you anyway.


这篇关于使用c#在excel中嵌入word文件并打开xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆