返回首页

试图细胞的数据添加到一个ArrayList,但得到"无法转换成Double类型为String的。

在细胞内的值是'1'的类型是一般。当我在工作簿中的头拉,他们所有的工作。

[EDIT1]当我输入我改变(杜)

col1.Add((string)(ws.Cells[currentRow, "A"] as Excel1.Range).Value2);
{C}
现在一切正常。

所以我现在的问题是,所有的数字是从Excel双打?

[EDIT2]我看了任务管理器中,有一大堆的EXCEL.EXE的开放,我怎么关闭呢?


public void ReadSheet()

		{

			try

			{

				Excel1.Application app = new Excel1.Application();

				Excel1.Workbook wb = app.Workbooks.Open(this.txtBoxFile.Text, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);

				Excel1.Sheets sheets = wb.Worksheets;

				Excel1.Worksheet ws = (Excel1.Worksheet)sheets[1];

				int currentRow = 2;

				while ((ws.Cells[currentRow, "A"] as Excel1.Range).Value2 != null && (ws.Cells[currentRow, "B"] as Excel1.Range).Value2 != null)

				{

					MessageBox.Show("1");

					col1.Add((string)(ws.Cells[currentRow, "A"] as Excel1.Range).Value2);

					col2.Add((string)(ws.Cells[currentRow, "B"] as Excel1.Range).Value2);

					col3.Add((string)(ws.Cells[currentRow, "C"] as Excel1.Range).Value2);

					col4.Add((string)(ws.Cells[currentRow, "D"] as Excel1.Range).Value2);

					MessageBox.Show("2");

					currentRow++;

				}

				GC.Collect();

				GC.WaitForPendingFinalizers();

				

				Marshal.FinalReleaseComObject(ws);

				Marshal.FinalReleaseComObject(sheets);

				

				wb.Close(false, Type.Missing, Type.Missing);

				Marshal.FinalReleaseComObject(wb);

				

				app.Quit();

				Marshal.FinalReleaseComObject(app);

			}

			catch(InvalidCastException ic)

			{

				MessageBox.Show(ic.Message, "CastException");

			}

			catch (Exception e)

			{

				MessageBox.Show(e.Message, "Exception");

			}

			finally

			{

				//

				ExcelToTxt();

			}

		}

回答

评论会员: 时间:2