Exce2007保存到文档库的问题的解决

现在的项目中遇到一个棘手的问题,用了很长的时间才找到解决的办法,所以把解决方案展示出来。

需求:把一个二进制字节数组(byte[])存到moss文档库中
环境:虚机和测试机都是(moss2007+vs2005),并且虚机自己作为域控,而测试机是域里的一台机器
实现:
  保存:public bool SaveData(string fileurl, byte[] bits)
        {
            bool save = false;
            using (SPSite site = new SPSite(fileurl))
            using (SPWeb web = site.OpenWeb())
            {
                SPFile file = web.GetFile(fileurl);
                file.SaveBinary(bits);
                save = true;
            }
            return save;
        }
获取的二进制数组:
        public byte[] GetWorkbookBits(WorkbookType type, string SeeionID)
        {
            try
            {
                ExcelService s = new ExcelService();
                Status[] status;
                s.Credentials = CredentialCache.DefaultCredentials;

                byte[] bits = s.GetWorkbook(SeeionID, type, out status);
                return bits;
            }
            catch (Exception soapEx)
            {

                throw new ApplicationException("The session has timed out.");

            }
        }
效果:虚机上保存成功,但是到测试机上生成的excel2007文件在打开时(下载到本地)有如下的错误:excel found unreadable content in <filename>,do you want to recover the contents of this workbook
我的解决:
1、比较web.config配置-----没有区别
2、比较office版本,开始的时候虚机是12.0.4518.1014,后来和服务器一样12.0.6300.5000
3、参考一下页面http://blogs.msdn.com/cumgranosalis/archive/2007/08/03/excel-found-unreadable-content-in-workbook-do-you-want-to-recover-the-contents-of-this-workbook.aspx

http://forums.msdn.microsoft.com/en-US/sharepointexcel/thread/f532c447-4427-4135-af4c-5a68b0b891df/


最终的解决办法很简单是file.SaveBinary(bits);方法中file文件由原来的“.xlsx”改成“.xlsb”格式文件。

见:http://www.cnblogs.com/fanwenxuan/archive/2008/08/01/1258423.html

你可能感兴趣的:(2007)