本文介绍了使用Excel = Microsoft.Office.Interop.Excel;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试打开一个excel文档,将某个单元格中的double读入我的程序,对该double进行额外求和然后更新单元格。


 我可以将excel doc读入我的程序并将所有内容输出到列表框中。我想得到一个单元格的值,添加但是cast是多余的,我只在我的列表框中获取系统对象。如何捕获一个单元格然后更新它?

 Excel.Application xlApp = new Excel.Application(); 
工作簿xlWorkbook = xlApp.Workbooks.Open(@"C:\ Users \cb \Desktop\Project \ Book1.xlsx");
_Worksheet xlWorksheet = xlWorkbook.Sheets [1];
范围xlRange = xlWorksheet.UsedRange;

Sheets excelSheets = xlWorkbook.Worksheets;
string currentSheet =" Sheet1" ;;
工作表excelWorksheet =(Excel.Worksheet)excelSheets.get_Item(currentSheet);

范围excelCell =
(Excel.Range)excelWorksheet.get_Range(" C5"," C5")。Value2;
listBox1.Items.Add(excelCell);





解决方案

I am trying to open an excel document, read the double in a certain cell into my program, do an addition sum on that double then update the cell.

  I can read the excel doc into my program and output all to a list box. I want to get the value of one cell, add but cast is redundant and I only get system object in my list box. How can I capture one cell then update it?

                                        Excel.Application xlApp	        = new Excel.Application();
					Workbook xlWorkbook		= xlApp.Workbooks.Open(@"C:\Users\cb\Desktop\Project \Book1.xlsx");
					_Worksheet xlWorksheet		= xlWorkbook.Sheets[1];
					Range xlRange			= xlWorksheet.UsedRange;

			Sheets excelSheets = xlWorkbook.Worksheets;
			string currentSheet = "Sheet1";
			Worksheet excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(currentSheet);

			Range excelCell =
			(Excel.Range)excelWorksheet.get_Range("C5", "C5").Value2;
			listBox1.Items.Add(excelCell); 



解决方案


这篇关于使用Excel = Microsoft.Office.Interop.Excel;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 22:07
查看更多