我正在尝试以zip格式导出RadGrid数据。为此,首先我以Excel格式导出数据,然后我尝试压缩它。但方法RadGrid.MasterTableView.ExportToExcel()
的返回类型为void
,因此我无法存储此Excel工作表的结果,以便将其作为输入传递给ZipPackage.
答案 0 :(得分:0)
据我所知,Radgrid没有Zip导出方法。 您可以做的是:在excel中导出文件,然后压缩excel文件(或您导出的任何其他类型)。 我就是这样做的:
protected void Button1_Click(object sender, EventArgs e)
{
foreach (GridColumn col in RadGrid1.MasterTableView.Columns)
{
//column you may like to excluded from the export process
if (col.UniqueName.Contains("EditCommandColumn") ||
col.UniqueName.Contains("attachments") ||
col.UniqueName.Contains("Upload") || col.UniqueName.Contains("Delete_col"))
{
col.Display = false;
}
else
{
col.Display = true;
}
}
foreach (GridFilteringItem item in RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem))
item.Visible = false;
RadGrid1.ExportSettings.ExportOnlyData = true;
RadGrid1.ExportSettings.FileName = "YourDesiredFileName";
RadGrid1.MasterTableView.ExportToExcel(); //this will be exported to the folder Download
Zip();
}
private void Zip()
{
//here your method with your preferred library to zip the file exported from the radgrid
//save it where you need it, rename it as you like it and delete the original excel file
}
答案 1 :(得分:0)
我相信您可以尝试挂钩OnGridExporting命令然后执行类似这样的操作
using (FileStream fs = File.Create("path you want to save the file")) {
Byte[] info = System.Text.Encoding.Default.GetBytes(e.ExportOutput);
//save it on the server
fs.Write(info, 0, info.Length);
}
将所有这些放在一个尝试中,捕获以查看文件权限问题并且文件已经存在问题。