我正在将数据从数据库导入 Excel 工作表。为此,我正在使用数据阅读器。excel工作表模板有一些宏和几个计算公式,它不是普通的excel工作表。所以只有在允许写入特定单元格的情况下,我才必须将数据写入 Excel 工作表。如果不是,则不应导入数据。
因此,为此,我有一个 XML 文件,其中说明我应该从哪一列开始写入以及应该在哪一行停止,我已经为许多工作表做了这个。但是在一张纸中,该行的第一个单元格是“只读的”(锁定的),其余的都是允许的写访问。
由于我使用 Datareader 从 DB 中获取了整行,因此我坚持需要写入其他单元格,而无需写入锁定的单元格。
我附上代码片段以供参考。
请帮助我这样做。
样本 ::
if (reader.HasRows)
{
minRow = 0;
minCol = 0;
Excel.Workbook SelWorkBook = excelAppln.Workbooks.Open(curfile, 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, false, false, false);
Excel.Sheets excelSheets = SelWorkBook.Worksheets;
Excel.Worksheet excelworksheet = (Excel.Worksheet)excelSheets.get_Item(CurSheetName);
// Process each result in the result set
while (reader.Read())
{
// Create an array big enough to hold the column values
object[] values = new object[reader.FieldCount];
// Add the array to the ArrayList
rowList.Add(values);
// Get the column values into the array
reader.GetValues(values);
int iValueIndex = 0;
// If the Reading Format is by ColumnByColumn
if (CurTaskNode.ReadFormat == "ColumnbyColumn")
{
minCol = 0;
// minRow = 0;
for (int iCol = 0; iCol < CurTaskNode.HeaderData.Length; iCol++)
{
// Checking whether the Header data exists or not
if (CurTaskNode.HeaderData[minCol] != "")
{
// Assigning the Value from reader to the particular cell in excel sheet
excelworksheet.Cells[CurTaskNode.DATA_MIN_ROW + minRow, CurTaskNode.DATA_MIN_COL + minCol] = values[iValueIndex];
iValueIndex++;
}
minCol++;
}
minRow++;
}SelWorkBook.Close(true, curfile, null);
请帮我解决这个问题。
谢谢你,
拉姆