数据导入Excel 生成图表,出现乱码, 急!!!!

cynthiabx 2009-02-23 11:31:30
是这样的
我要将一段sql的执行结果导入到Excel中并生成图表
但是在导出后面坐标轴上文字会出现乱码,我的机器是好的,但是到了测试环境就会出问题,请问是什么原因呢?谢谢
代码如下:


ApplicationClass myApplication = null;
Workbook myWorkBook = null;
Worksheet mySheet = null;
string OLDDBConnectionString = @"OLEDB;Provider=MSDAORA.1;Password={0};Persist Security Info=True;User ID={1};Data Source={2};
Current Language=us_english;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;
Workstation ID=***[我的机器名];Use Encryption for Data=False;Tag with column collation when possible=False";

OLDDBConnectionString = string.Format(OLDDBConnectionString,
this.m_ImageInfo.DataSource.Password,
this.m_ImageInfo.DataSource.UserName,
this.m_ImageInfo.DataSource.Database);
try
{
myApplication = new ApplicationClass();
myWorkBook = myApplication.Workbooks.Open(this.m_ImageInfo.TemplateFileName, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
mySheet = (Worksheet)(myWorkBook.Worksheets[1]);

OLEDBConnection myOLEDBConnection = myWorkBook.Connections[1].OLEDBConnection;

myOLEDBConnection.BackgroundQuery = false;
myOLEDBConnection.CommandText = this.m_ImageInfo.DataSource.Sql;
myOLEDBConnection.CommandType = XlCmdType.xlCmdSql;
myOLEDBConnection.Connection = OLDDBConnectionString;
myOLEDBConnection.RefreshOnFileOpen = false;
myOLEDBConnection.SavePassword = false;
myOLEDBConnection.SourceConnectionFile = "";
myOLEDBConnection.ServerCredentialsMethod = XlCredentialsMethod.xlCredentialsMethodStored;
myOLEDBConnection.AlwaysUseConnectionFile = false;


myWorkBook.Connections[1].Refresh();
// Set multi-language title.
PivotTable myPivotTable = (PivotTable)mySheet.PivotTables(1);

for (int i = 0; i < this.m_ImageInfo.TitleLanguageList.Count; i++)
{
((PivotItem)(myPivotTable.DataPivotField.PivotItems(i + 1))).Caption = this.m_ImageInfo.TitleLanguageList[i];
}
imageName = Guid.NewGuid().ToString() + "." + this.m_ImageInfo.ImageType.ToLower();
// Check output directory.
if (!Directory.Exists(this.m_ImageInfo.ImageFilePath))
Directory.CreateDirectory(this.m_ImageInfo.ImageFilePath);


Chart activeChart = ((ChartObject)mySheet.ChartObjects(1)).Chart;
Axis valueAxis = (Axis)(activeChart.Axes(XlAxisType.xlValue, XlAxisGroup.xlPrimary));
if (valueAxis.HasTitle)
{
valueAxis.AxisTitle.Text = this.m_ImageInfo.YAxisTitle;
}
Axis categoryAxis = (Axis)activeChart.Axes(XlAxisType.xlCategory, XlAxisGroup.xlPrimary);
if (categoryAxis.HasTitle)
{
categoryAxis.AxisTitle.Text = this.m_ImageInfo.XAxisTitle;
}

((ChartObject)mySheet.ChartObjects(1)).Width = this.m_ImageInfo.ImageWidth;

((ChartObject)mySheet.ChartObjects(1)).Chart.Export(this.m_ImageInfo.ImageFilePath + @"\" + imageName, this.m_ImageInfo.ImageType, Missing.Value);
...全文
395 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
jojoMyiyi 2011-05-14
  • 打赏
  • 举报
回复
话说 我的导入到excel里也出乱码!
cynthiabx 2009-02-23
  • 打赏
  • 举报
回复
自己顶一下

62,039

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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