求助各位,先把代码贴上去
[code=C#][/code
public void ExportSchemeDataToExcel() {
Microsoft.Office.Interop.Excel.Application ExcelApp = new Microsoft.Office.Interop.Excel.Application();
if (ExcelApp == null)
{
MessageBox.Show("无法创建Excel对象,可能您的机子未安装Excel");
return;
}
Microsoft.Office.Interop.Excel.Workbooks mywbs = ExcelApp.Workbooks;
Microsoft.Office.Interop.Excel.Workbook workbook = mywbs.Add(true);
Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.ActiveSheet;
ExcelApp.DisplayAlerts = false;
worksheet.Name = "mySchemeData";
ExcelApp.Visible=false;
for (int i = 0; i < 8; i++)
{
if (i == 0)
{
worksheet.Cells[1, i + 1] = "方案";
for (int j = 0; j < Chromsome; j++)
{
worksheet.Cells[2, i + 1] += Convert.ToString(currentbest.chrom[j])+ ",";
}
}
if (i == 1)
{
worksheet.Cells[1, i + 1] = "系统a";
worksheet.Cells[ 2, i + 1] = systemIndex[2].ToString();
}
if (i == 2)
{
worksheet.Cells[1, i + 1] = "系统b";
worksheet.Cells[ 2, i + 1] = systemIndex[0].ToString();
}
if (i == 3)
{
worksheet.Cells[1, i + 1] = "系统c";
worksheet.Cells[2, i + 1] = systemIndex[4].ToString();
}
if (i == 4)
{
worksheet.Cells[1, i + 1] = "系统d";
worksheet.Cells[2, i + 1] = systemIndex[5].ToString();
}
if (i == 5)
{
worksheet.Cells[1, i + 1] = "系统f";
worksheet.Cells[2, i + 1] = systemIndex[7].ToString();
}
if (i == 6)
{
worksheet.Cells[1, i + 1] = "系统g";
worksheet.Cells[2, i + 1] = Cs.ToString();
}
if (i == 7)
{
worksheet.Cells[1, i + 1] = "系统h";
worksheet.Cells[2, i + 1] = Cm.ToString();
} Microsoft.Office.Interop.Excel.Range range = worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[1, 8]);
range.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
range.VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter;
range.EntireColumn.AutoFit();
range.EntireRow.AutoFit(); string workPath = System.Windows.Forms.Application.StartupPath;
System.DateTime date = System.DateTime.Now;
string time = date.ToString("数据保存(H时mm分ss秒)", DateTimeFormatInfo.InvariantInfo);
string savePath = workPath + time + "-" + "SchemeDataDetail" + ".xlsx";
workbook.SaveCopyAs(savePath);
KillProcess(ExcelApp);
}
]
远程过程调用失败。 (异常来自 HRESULT:0x800706BE) 未处理的COMException
遇到上述问题,请帮忙解决!
[code=C#][/code
public void ExportSchemeDataToExcel() {
Microsoft.Office.Interop.Excel.Application ExcelApp = new Microsoft.Office.Interop.Excel.Application();
if (ExcelApp == null)
{
MessageBox.Show("无法创建Excel对象,可能您的机子未安装Excel");
return;
}
Microsoft.Office.Interop.Excel.Workbooks mywbs = ExcelApp.Workbooks;
Microsoft.Office.Interop.Excel.Workbook workbook = mywbs.Add(true);
Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.ActiveSheet;
ExcelApp.DisplayAlerts = false;
worksheet.Name = "mySchemeData";
ExcelApp.Visible=false;
for (int i = 0; i < 8; i++)
{
if (i == 0)
{
worksheet.Cells[1, i + 1] = "方案";
for (int j = 0; j < Chromsome; j++)
{
worksheet.Cells[2, i + 1] += Convert.ToString(currentbest.chrom[j])+ ",";
}
}
if (i == 1)
{
worksheet.Cells[1, i + 1] = "系统a";
worksheet.Cells[ 2, i + 1] = systemIndex[2].ToString();
}
if (i == 2)
{
worksheet.Cells[1, i + 1] = "系统b";
worksheet.Cells[ 2, i + 1] = systemIndex[0].ToString();
}
if (i == 3)
{
worksheet.Cells[1, i + 1] = "系统c";
worksheet.Cells[2, i + 1] = systemIndex[4].ToString();
}
if (i == 4)
{
worksheet.Cells[1, i + 1] = "系统d";
worksheet.Cells[2, i + 1] = systemIndex[5].ToString();
}
if (i == 5)
{
worksheet.Cells[1, i + 1] = "系统f";
worksheet.Cells[2, i + 1] = systemIndex[7].ToString();
}
if (i == 6)
{
worksheet.Cells[1, i + 1] = "系统g";
worksheet.Cells[2, i + 1] = Cs.ToString();
}
if (i == 7)
{
worksheet.Cells[1, i + 1] = "系统h";
worksheet.Cells[2, i + 1] = Cm.ToString();
} Microsoft.Office.Interop.Excel.Range range = worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[1, 8]);
range.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
range.VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter;
range.EntireColumn.AutoFit();
range.EntireRow.AutoFit(); string workPath = System.Windows.Forms.Application.StartupPath;
System.DateTime date = System.DateTime.Now;
string time = date.ToString("数据保存(H时mm分ss秒)", DateTimeFormatInfo.InvariantInfo);
string savePath = workPath + time + "-" + "SchemeDataDetail" + ".xlsx";
workbook.SaveCopyAs(savePath);
KillProcess(ExcelApp);
}
]
远程过程调用失败。 (异常来自 HRESULT:0x800706BE) 未处理的COMException
遇到上述问题,请帮忙解决!
{"RPC 服务器不可用。 (异常来自 HRESULT:0x800706BA)"}
断点调试定位在“worksheet.Cells[1, i + 1] = "系统a"; "这句