你好,附件中是转换后的json数据,mbgs数据是通过下面: /// <summary>
/// JSON转化为内存流
/// </summary>
/// <param name="json"></param>
public MemoryStream FromJSON(string mbgs)
{
try
{
json = DecompressString(mbgs);
string m_BaseAddressExcelIO = "http://192.168.1.3";
if (!string.IsNullOrEmpty(m_BaseAddressExcelIO))
{
// 通过远程服务获取json数据
return FromJSON(json, m_BaseAddressExcelIO);
}
else
{
return null;
}
}
catch (Exception ex)
{
throw ex;
}
}
public string DecompressString(string str)
{
try
{
if (string.IsNullOrEmpty(str) || str[0] == '{') return str;
string compressString = "";
//byte[] compressBeforeByte = Encoding.GetEncoding("UTF-8").GetBytes(str);
byte[] compressBeforeByte = Convert.FromBase64String(str);
byte[] compressAfterByte = Decompress(compressBeforeByte);
compressString = Encoding.GetEncoding("UTF-8").GetString(compressAfterByte);
return compressString;
}
catch (Exception ex)
{
throw ex;
}
}
这个方法转换成json数据的。转化后再通过下面
/// <summary>
/// JSON转化为内存流
/// </summary>
/// <param name="json"></param>
private MemoryStream FromJSON(string json, string excelIOBaseAddress)
{
try
{
if (string.IsNullOrEmpty(json)) return null;
EPWebClient webClient = new EPWebClient();
System.Collections.Specialized.NameValueCollection formData =
new System.Collections.Specialized.NameValueCollection();
formData["type"] = "application/json";
formData["data"] = "{\"spread\":" + json + "}";
string uri = excelIOBaseAddress + "/SourceCode_ExcelIO/xsapi/export";
byte[] result = webClient.UploadValues(uri, "POST", formData);
return BytesToStream(result); ;
}
catch (Exception ex)
{
throw ex;
}
}
这个方法转换为内存流,然后再
using (var stream = FromJSON(jsonData))
{
if (stream == null) return;
gcSpreadSheet.OpenExcel(stream);
stream.Close();
}
OpenExcel(stream)打开。
|
|