哪位大神看看下面这段代码有什么有关问题?代码没有异常,运行时出现有关问题,本人初学者勿喷
哪位大神看看下面这段代码有什么问题?代码没有错误,运行时出现问题,本人菜鸟勿喷!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using Excel=Microsoft.Office.Interop.Excel;
namespace 窗体
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = Coordinate.GetCoordinate(panel1.CreateGraphics());//这里调用了一个Coordinate类文件,具体代码没写
}
float[,] y = new float[10, 2];
float[]w = new float[10];
PointF[]points = new PointF[10];
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog fr= new OpenFileDialog();
string filename="";
fr.Filter = "xls文件|*.xls";
fr.RestoreDirectory = true;
if (fr.ShowDialog() == DialogResult.OK)
{
filename = fr.FileName;
}
if (filename != "")
{
try
{
Excel.Application xApp = new Excel.Application();
xApp.Visible = true;
Excel.Workbook xBook;
Excel.Worksheet xSheet;
xBook = xApp.Workbooks.Open(@filename,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value);
xSheet = (Excel.Worksheet)xBook.Sheets[1];
for (int i = 0; i < 10; ++i)
{
for (int j = 0; j < 2; ++j)
{
Excel.Range reg = (Excel.Range)xSheet.Cells[i + 1, j + 1];
y[i,j] = Convert.ToSingle(reg.Value2.ToString());
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using Excel=Microsoft.Office.Interop.Excel;
namespace 窗体
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = Coordinate.GetCoordinate(panel1.CreateGraphics());//这里调用了一个Coordinate类文件,具体代码没写
}
float[,] y = new float[10, 2];
float[]w = new float[10];
PointF[]points = new PointF[10];
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog fr= new OpenFileDialog();
string filename="";
fr.Filter = "xls文件|*.xls";
fr.RestoreDirectory = true;
if (fr.ShowDialog() == DialogResult.OK)
{
filename = fr.FileName;
}
if (filename != "")
{
try
{
Excel.Application xApp = new Excel.Application();
xApp.Visible = true;
Excel.Workbook xBook;
Excel.Worksheet xSheet;
xBook = xApp.Workbooks.Open(@filename,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value);
xSheet = (Excel.Worksheet)xBook.Sheets[1];
for (int i = 0; i < 10; ++i)
{
for (int j = 0; j < 2; ++j)
{
Excel.Range reg = (Excel.Range)xSheet.Cells[i + 1, j + 1];
y[i,j] = Convert.ToSingle(reg.Value2.ToString());
}