在Excel中插入特定单元格中的文本c# [英] Insert text in specific cell in Excel c#

查看:99
本文介绍了在Excel中插入特定单元格中的文本c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在第5行ist列中插入文本,在第5行第2列中插入另一个文本...我该怎么做?以下是我使用的代码,并超出范围异常:

I need to insert text in 5th row ist column and another text in 5th row 2nd column... How do I do this? Below is the code am using and get out of range exception:

Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
Excel.Worksheet xlWorkSheet2;
Excel.Worksheet xlWorkSheet3;
Excel.Range oRange;

xlApp = new Excel.Application();

xlWorkBook = xlApp.Workbooks.Add(misValue);

xlWorkSheet2 = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlWorkSheet2.Name = "The chart sheet";

xlWorkSheet2.Cells[5, 1] = "First Name";
xlWorkSheet2.Cells[5,2] = "Last Name";  


推荐答案

在上面的单元格插入之前,您必须添加一个工作表

Before the cell insertion above you have to add a worksheet

Excel.Application excelApplication = new Excel.Application();
Excel.Workbook excelWorkBook = excelApplication.Workbooks.Add();
Excel.Worksheet wkSheetData = excelWorkBook.ActiveSheet;
excelApplication.Cells[5, 2] = "TextField";

我希望这有助于

这篇关于在Excel中插入特定单元格中的文本c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆