How to write in excel cells using DataReader if a specific cell is "ReadOnly" using C #

I am using DataReader to write data to excelsheet cells. I have no problem until the camera writes prevail. But in one case, only one cell is readonly, and the rest of the cells are writable.

For example: 10 * 10 cells, only the first cell is read-only. therefore, I delete this cell and write it to the remaining cells. But with a data reader, it writes a whole line at a time .. so how can I achieve this with C #?

Team Leader (required) , , , , , , , , , 
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , , ,

therefore, the first cell should not be written by datareader. Please help me with this.

if (reader.HasRows)
{
    minRow = 0;
    minCol = 0;
    // 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++;
        }
    }
}

Thanks Ramm

+3
2

google, , , /, : ,

AllowEdit , :

// Assigning the Value from reader to the particular cell in excel sheet      
Excel.Range c = (Excel.Range)excelworksheet.Cells[CurTaskNode.DATA_MIN_ROW + minRow, CurTaskNode.DATA_MIN_COL + minCol];
if (c.AllowEdit) c.Value2 = values[iValueIndex];

// 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];
+1

, excel #, .

: () abcxyz User1 user2 Focal dfgidf user23 user3

... excel ( ()) readonly, , excel

                            abcxyz  User1   user2
Customer Interface Focal    dfgidf  user23  user3.....
.....

... .

Microsoft.Office.Interop.Excel.Workbook SelWorkBook = excelappln1.Workbooks.Open(
    curfile,
    0, false, 5, "", "", false,
    Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,
    "", true,
    false, 0, false, false, false);

Microsoft.Office.Interop.Excel.Sheets excelSheets = SelWorkBook.Worksheets;
Microsoft.Office.Interop.Excel.Worksheet excelworksheet =(Microsoft.Office.Interop.Excel.Worksheet)excelSheets.get_Item(CurSheetName);

Microsoft.Office.Interop.Excel.Range excelRange = excelworksheet.UsedRange;

if ((!excelworksheet.Cells[CurTaskNode.DATA_MIN_ROW + minRow, CurTaskNode.DATA_MIN_COL + minCol]).Locked)
{
    // 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++;
}

, if 1 '!' ""

, , , .

0

Source: https://habr.com/ru/post/1711651/


All Articles