我的代码如下。基本上,我正在读取一个 excel 文件并将其内容存储到一个对象数组中。然后,我使用 switch case 语句来执行不同的操作。在下面检查我的代码:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
using System.Drawing;
using System.ComponentModel;
using Excel = Microsoft.Office.Interop.Excel;
using Microsoft.Office.Interop.Excel;
namespace Excel1
{
class Program
{
public static void Main(string[] args)
//public void ExcelOps()
{
//string str;
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"D:/WebServiceTemplate.xlsx");
Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
Excel.Range xlRange = xlWorksheet.UsedRange;
int rowCount = xlRange.Rows.Count;
int colCount = xlRange.Columns.Count;
int numSheets = xlWorkbook.Sheets.Count;
//
// Iterate through the sheets. They are indexed starting at 1.
//
for (int sheetNum = 1; sheetNum <=1; sheetNum++)
{
Worksheet sheet = (Worksheet)xlWorkbook.Sheets[sheetNum];
//
// Take the used range of the sheet. Finally, get an object array of all
// of the cells in the sheet (their values).
//
object[,] valueArray = (object[,])xlRange.get_Value(XlRangeValueDataType.xlRangeValueDefault);
//
// Do something with the data in the array with a custom method.
//
ProcessInput(valueArray);
}
}
public static void ProcessInput(object[,] valueArray)
{
foreach (var value in valueArray)
{
switch ((string)value.ToString())
{
case "ITemplate.GetAllTemplate":
{
//ITemplate.GetAllTemplate
break;
}
case "ITask.GetTaskInstanceFromTemplate":
{
//ITask.GetTaskInstanceFromTemplate
break;
}
case "CreateTask":
{
//CreateTask
break;
}
case "UpdateDatabase":
{
//UpdateDatabase
break;
}
case "GetTaskStatus":
{
//GetTaskStatus
break;
}
case "VerifyValue":
{
//VerifyValue
}
break;
}
}
}
}
}
当我构建它时,我得到一个错误
对象引用未设置为对象的实例。
错误出现在 switch 语句中
有人可以帮我弄这个吗?