水晶报表导出文件名自定义问题

yinhaichao2008 2011-08-28 03:29:47
水晶报表导出文件名自定义问题
我bind后给控件赋值了中文ID,导出时也可以显示那个文件名,但是是乱码。。怎么解决啊,跪求
...全文
184 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
阿泰 2011-08-29
  • 打赏
  • 举报
回复
如果纯依赖于控件的导出功能的话,尝试更改页面编码编码试试
比如utf8,gb2312之类
  • 打赏
  • 举报
回复
参考
导出页面

//载入报表参数
private void ReportInput()
{
DataTable dt = new DataTable();
if ((CheckShop.Checked == true) && (DDLShop.SelectedValue != ""))
{
string shop = DDLShop.SelectedItem.Value.ToString().Trim();
string text = DDLCX.SelectedItem.Value.ToString().Trim();
string value = string.Empty;
if (text == "null")
{
value = null;
}
else
{
value = DDLCon.SelectedItem.Value.ToString().Replace(" 0:00:00", "");
}
dt = service.yyhz(jbtj, "tbl_jiebantongji", "shop_no", shop, text, value);
}
else
{
dt = service.yyhz(jbtj, "tbl_jiebantongji");
}

string reportPath = Server.MapPath("~/Reports/jiebantongji.rpt");
report.Load(reportPath);
report.SetDatabaseLogon("sa", "");
report.SetDataSource(dt);
}
/// <summary>
/// 报表导出功能实现
/// </summary>
protected void btnSave_Click(object sender, EventArgs e)
{
ReportInput();
//导出类型
string contenttype = string.Empty;
//导出的文件类型
string fileType = DDLSaveType.SelectedValue;
//导出的文件路径
string ExportPath;
//导出的文件名称
string FileName;
ExportPath = Request.PhysicalApplicationPath + "报表/" + ReportName.AddDate() + "/";
if (!Directory.Exists(ExportPath))
{
System.IO.Directory.CreateDirectory(Request.PhysicalApplicationPath + "报表/" + ReportName.AddDate() + "/");
}
FileName = "结班统计报表" + ReportName.AddDate();
//FileName = Request.MapPath(".")+"\\报表\\" + ReportName.AddDate() + "\\" + FileName + "." + fileType;

DiskFileDestinationOptions diskFile = new DiskFileDestinationOptions();
//diskFile.DiskFileName = FileName;
//导出为磁盘文件
ExportOptions options = report.ExportOptions;
options.ExportDestinationOptions = diskFile;
options.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
switch (DDLSaveType.SelectedItem.Value)
{
case "pdf":
contenttype = "application/pdf";
options.ExportFormatType = ExportFormatType.PortableDocFormat;
break;
case "doc":
Response.ContentType = "application/ms-word";
options.ExportFormatType = ExportFormatType.WordForWindows;
break;
case "xls":
contenttype = "application/ms-excel";
options.ExportFormatType = ExportFormatType.Excel;
break;
default:
contenttype = "application/ms-excel";
options.ExportFormatType = ExportFormatType.Excel;
break;
}

FileName = FileName + "." + DDLSaveType.SelectedItem.Value;
diskFile.DiskFileName = ExportPath + FileName;

//导出操作
report.Export();
if (MessageBox.Show(null, "数据已保存到服务器,是否下载到本地?", "信息提示:", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1,MessageBoxOptions.ServiceNotification) == DialogResult.Yes)
{
Response.Redirect("DownloadFile.aspx?FileName=" + diskFile.DiskFileName);
}
ReportLoad();
ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), null, "alert('报表已保存到服务器!')", true);
}


下载页面

protected void Page_Load(object sender, EventArgs e)
{
string fileroot=Request.QueryString["FileName"].ToString();
string type = getFileType(fileroot);
HttpResponse ht = Page.Response;
UserCom.DownloadFile(ht,fileroot,type);
}

public static string getFileType(string fileroot)
{
string newstr = string.Empty;
int det = 0;
char[] rootchar = fileroot.ToCharArray();
for (int i = 0; i < rootchar.Length; i++)
{
if (rootchar[i].ToString() == ".")
{
det = i;
}
}
for (int j = det; j < rootchar.Length; j++)
{
newstr += rootchar[j].ToString();
}

return newstr;
}




处理类库

#region 报表文件下载

/// <summary>
/// 报表下载到客户端
/// </summary>
/// <param name="response"></param>
/// <param name="serverPath"></param>
/// <param name="type"></param>
public static void DownloadFile(HttpResponse response,string serverPath,string type)
{


FileStream fs = null;
try
{
fs = File.OpenRead(serverPath);
byte[] buffer = new byte[1024];
long count = 1024;
response.Buffer = true;

response.Charset = "GB2312";
response.ContentEncoding = System.Text.Encoding.UTF7;
response.AppendHeader("Content-Disposition", "attachment;filename =" + HttpUtility.UrlEncode(serverPath, Encoding.UTF8).ToString());
response.ContentType = "";
switch (type)
{
case ".pdf":
response.ContentType = "application/pdf";
break;
case ".doc":
response.ContentType = "application/ms-word";
break;
case ".xls":
response.ContentType = "application/ms-excel";
break;
default:
response.ContentType = "application/all";
break;
}
while (count == 1024)
{
count = fs.Read(buffer, 0, 1024);
response.BinaryWrite(buffer);
}
}
catch {
}
finally
{
fs.Close();
}
}

#endregion




以上是一个报表导出 Excel word pdf 文件的处理,可以自定义文件名

4,819

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 图表区
社区管理员
  • 图表区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧