我有一个将生成excel报告的代码。我正在使用ASP.NET MVC 4,并且excel导出工作正常,但是当将其翻译为带有文化“ fr-FR”的法语时,货币十进制分隔符excel是'。'而不是“,”。
当我检查区域性详细信息时,它显示 culturename =“ fr-FR” 和 CurrencyDecimalSeparator =“,” 和区域性。LCID= 1036。
当我导出到PDF时,CurrencyDecimalSeparator为',',但为'。'。用于导出到Excel。 我尝试了rd.ExportToHttpResponse(ExportFormatType.Excel)和 rd.ExportToHttpResponse(ExportFormatType.ExcelRecord)
是否可以解决此问题。
请找到导出到excel的代码
public ActionResult ExportReport(string exportFormat, string reportName)
{
try
{
ReportDetails currentReport = new ReportDetails();
currentReport = GetReportSessionDetails(reportName);
// Get crystal report file..
string rptFile = Convert.ToString(currentReport.ReportFile);
string resourcePath = string.Empty;
if (ConfigurationManager.AppSettings["CrystalReportResourcePath"] != null)
resourcePath = Convert.ToString(ConfigurationManager.AppSettings["CrystalReportResourcePath"]);
string filter = Convert.ToString(currentReport.FilterQuery);
//get data for report from DB
var _reportData = GetData(filter);
DataSet ds = _reportData;
// Load crystal report from the path..
ReportDocument rd = new ReportDocument();
rd.Load(Path.Combine(resourcePath, rptFile));
rd.DataSourceConnections.Clear();
rd.SetDataSource(ds.Tables["Main"]);
// Set parameter..
rd.SetParameter(reportName);
var culture = CultureInfo.CurrentCulture;
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
var currentRegion = new RegionInfo(culture.LCID);
CrystalDecisions.Shared.SharedUtils.RequestLcid = culture.LCID;
Response.Buffer = false;
Response.ClearContent();
Response.ClearHeaders();
Stream stream;
string fileName = rptFile.TrimEnd(".rpt");
// Export to different formats given..
switch (exportFormat)
{
// if format id PDF, show in the window..
case "PDF":
ExportPDF(rd, fileName);
return Content("");
case "XLS":
ExportExcel(rd, fileName);
return Content("");
default:
ExportPDF(rd, fileName);
return Content("");
}
}
catch (Exception ex)
{
CrystalReportExceptionHandler.ShowError(ex, ex.Message);
return Redirect("/Content/Reporting/ReportViewer.aspx");
}
}
public void ExportPDF(ReportDocument rd, string fileName)
{
System.IO.Stream oStream = null;
byte[] byteArray = null;
oStream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
byteArray = new byte[oStream.Length];
oStream.Read(byteArray, 0, Convert.ToInt32(oStream.Length - 1));
rd.Close();
rd.Dispose();
rd = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
Response.ContentType = "application/pdf";
// File name for save as pdf..
Response.AppendHeader("Content-Disposition", "filename=" + fileName + ".pdf");
Response.BinaryWrite(byteArray);
Response.Flush();
Response.Close();
}
public void ExportExcel(ReportDocument rd, string fileName)
{
var response = System.Web.HttpContext.Current.Response;
rd.ExportToHttpResponse(ExportFormatType.Excel, response, false, fileName + ".xls");
rd.Close();
rd.Dispose();
rd = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
Response.End();
Response.Clear();
Response.Buffer = true;
Response.Flush();
Response.Close();
}