如何用Delphi 删除Execel 中的第一列?

解决方案 »

  1.   

    这是表尾设置综合列。
            Sheet.Cells[nCurrRow,1] := pTail;
            sheet.range[sheet.cells[nCurrRow, 1],sheet.cells[nCurrRow,nCols]].Select; //选择该列
            Excelid.selection.HorizontalAlignment := $FFFFEFF4;                               //居中
            Excelid.selection.MergeCells := True;
      

  2.   

    在EXCEL中录一个宏,看一下代码,抄到DELPHI中就OK了。
      

  3.   

    删除Execel 中的第一列
    ExcelApp.ActiveSheet.Columns[1].Delete;
      

  4.   

    ExcelApp.ActiveSheet.Columns[1].Delete;
      

  5.   

    我的代码如下:好像不是使用的不是上面的对象。请大家看看:
         try
              Excelid := CreateOLEObject('Excel.Application');
            except
              Application.MessageBox('Excel没有安装!', '提示信息', MB_OK+MB_ICONASTERISK+MB_DEFBUTTON1+MB_APPLMODAL);
              Exit;
            end;
            Excelid.Visible := false;        Excelid.WorkBooks.Add;        Sheet := Excelid.Workbooks[1].WorkSheets[1];        nCurrRow := 1;
            if SePTitle <> '' then begin
              Sheet.Cells[1,1] := SePTitle;
              sheet.range[sheet.cells[2, 1],sheet.cells[2,nCols]].Select; //选择该列
              //Excelid.selection.HorizontalAlignment := $FFFFEFF4;                               //居中
              Excelid.selection.MergeCells := True;
              //表体(包括表头)
              nCurrRow := 2;
            end;
            ProgressBar1.Position :=0;
            ProgressBar1.Max :=mGrid.RowCount;
            for i:=0 to mGrid.RowCount-1 do begin
              ProgressBar1.Position :=ProgressBar1.Position +1;
              nCurrCol := 1;
              for j:=0 to mGrid.ColCount-1 do begin
                if mGrid.ColWidths[j]>0 then begin
                   if (j=2)or (j=4) or( j=5) then begin
                    Sheet.Cells[nCurrRow,nCurrCol].NumberFormatLocal := '@';
                    Sheet.Cells[nCurrRow,nCurrCol] := mGrid.Cells[j,i];
                  end else begin
                    Sheet.Cells[nCurrRow,nCurrCol] := mGrid.Cells[j,i];              end;
                  nCurrCol := nCurrCol + 1;
                end;
              end;
              nCurrRow := nCurrRow + 1;
            end;
              Sheet.Columns[1].Delete;
    //        ExcelApp.ActiveSheet.Columns[1].Delete
            //表尾文字
            Sheet.Cells[nCurrRow,1] := pTail;
            sheet.range[sheet.cells[nCurrRow, 1],sheet.cells[nCurrRow,nCols]].Select; //选择该列        Excelid.selection.HorizontalAlignment := $FFFFEFF4;                               //居中
            Excelid.selection.MergeCells := True;        try
              sheet.cells[1,1].Select;          Excelid.Workbooks[1].SaveAs(FileName);          Excelid.Workbooks[1].close;
              Excelid.Quit;
            except
              Excelid.Quit;        //有时写完后立即退出,但写进程还占用着该文件,不允许退出,所以这里再退出一次
            end;                   //实际上就是设一点点延迟,
            Excelid := Unassigned;
           end else begin
            strlist.Add(pTitle);
            for i:=0 to mGrid.rowcount -1 do begin
              for j:=0 to mGrid.ColCount - 1 do begin
                str := str + mGrid.Cells[j,i] + #9;
              end;
              strList.Add(str);
              str := '';
            end;
            strlist.Add(pTail);
            strList.SaveToFile(Filename);
            strlist.Free;
            strlist := nil;
        end;如何进行删除。?