1

我需要减少列中的单元格值,例如“250-1824-02”到“250-1824”,并使用 c# 将新值更新为同一个 Excel 表中的新列。请帮忙

我已将编码生成到以下级别:

Excel.Workbook xlWorkBook;
            Excel.Worksheet xlWorkSheet;
            object misValue = System.Reflection.Missing.Value;
            xlApp = new Excel.Application();
            xlApp.Visible = false;
            xlWorkBook = xlApp.Workbooks.Open(textBox1.Text, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);
            xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
4

1 回答 1

1
Excel.Application xlApp;
    Excel.Workbook xlWorkBook;
    Excel.Worksheet xlWorkSheet;
    object misValue = System.Reflection.Missing.Value;
    xlApp = new Excel.Application();
    xlWorkBook = xlApp.Workbooks.Open(ExcelFile, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);
    xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);



Microsoft.Office.Interop.Excel.Range range = xlWorkSheet.Cells.SpecialCells(
                Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeLastCell, Type.Missing);

        string value = string.Empty;
        for (int Loop = 1; Loop <= range.Row; Loop++)
        {
            value = Convert.ToString(xlWorkSheet.Range["A" + Loop, "A" + Loop].get_Value(misValue));
            xlWorkSheet.Range["B" + Loop, "B" + Loop].set_Value(misValue, value.Remove(8, 3));
        }  
于 2012-10-16T10:14:26.557 回答