我用DBGridEh导出excel中,字段长度为1000,但是某些值导不出,字段长度350就到不出,有无好解决方法
 if sdlgExport.Execute then
    SaveDBGridEhToExportFile(TDBGridEhExportAsXLS,DBGridEh1, sdlgExport.FileName, True);
帮帮忙!!!!!!!!!!!!

解决方案 »

  1.   

    自己用ole导出到excel,你本身的数据长度,没有超过excel的限制.
      

  2.   

    对 不行就切分吧  我现在也做DELPHI 正用DBGrid呢
      

  3.   

    与EXCEL没关系
    看看控件事件吧
    或者用别的方法导出
      

  4.   

    procedure TDBGridEhExport.ExportToStream(AStream: TStream; IsExportAll: Boolean);
    var i: Integer;
      ColList: TColumnsEhList;
      ASelectionType: TDBGridEhSelectionType;
    begin
      Stream := AStream;
      try
        with DBGridEh do
        begin
          if IsExportAll then ASelectionType := gstAll else ASelectionType := Selection.SelectionType;
          if ASelectionType = gstNon then Exit;
          with DataSource.Dataset do
          begin
            DisableControls;
            SaveBook;
            try
              case ASelectionType of
                gstRecordBooks:
                  begin
                    ExpCols := VisibleColumns;
    //                FooterValues := AllocMem(SizeOf(Currency) * ExpCols.Count * DBGridEh.FooterRowCount);
                    SetLength(FooterValues, ExpCols.Count * DBGridEh.FooterRowCount);
                    WritePrefix;
                    if dgTitles in Options then WriteTitle(VisibleColumns);
                    for i := 0 to Selection.Rows.Count - 1 do
                    begin
                      Book := Selection.Rows[I];
                      CalcFooterValues;
                      WriteRecord(VisibleColumns);
                    end;
                    for i := 0 to FooterRowCount - 1 do WriteFooter(VisibleColumns, i);
                  end;
                gstRectangle:
                  begin
                    ColList := TColumnsEhList.Create;
                    try
                      for i := Selection.Rect.LeftCol to Selection.Rect.RightCol do
                        if Columns[i].Visible then
                          ColList.Add(Columns[i]);
                      ExpCols := ColList;
    //                  FooterValues := AllocMem(SizeOf(Currency) * ExpCols.Count * DBGridEh.FooterRowCount);
                      SetLength(FooterValues, ExpCols.Count * DBGridEh.FooterRowCount);
                      WritePrefix;
                      if dgTitles in Options then WriteTitle(ColList);
                      Book := Selection.Rect.TopRow;
                      while True do
                      begin
                        WriteRecord(ColList);
                        CalcFooterValues;
    //                    if CompareBooks(Pointer(Selection.Rect.BottomRow), Pointer(Book)) = 0 then Break;
                        if DataSetCompareBooks(DBGridEh.DataSource.Dataset, Selection.Rect.BottomRow, Book) = 0 then Break;
                        Next;
                        if Eof then Break;
                      end;
                      for i := 0 to FooterRowCount - 1 do WriteFooter(ColList, i);
                    finally
                      ColList.Free;
                    end;
                  end;
                gstColumns:
                  begin
                    ExpCols := Selection.Columns;
    //                FooterValues := AllocMem(SizeOf(Currency) * ExpCols.Count * DBGridEh.FooterRowCount);
                    SetLength(FooterValues, ExpCols.Count * DBGridEh.FooterRowCount);
                    WritePrefix;
                    if dgTitles in Options then WriteTitle(Selection.Columns);
                    First;
                    while Eof = False do
                    begin
                      WriteRecord(Selection.Columns);
                      CalcFooterValues;
                      Next;
                    end;
                    for i := 0 to FooterRowCount - 1 do WriteFooter(Selection.Columns, i);
                  end;
                gstAll:
                  begin
                    ExpCols := VisibleColumns;
    //                FooterValues := AllocMem(SizeOf(Currency) * ExpCols.Count * DBGridEh.FooterRowCount);
                    SetLength(FooterValues, ExpCols.Count * DBGridEh.FooterRowCount);
                    WritePrefix;
                    if dgTitles in Options then WriteTitle(VisibleColumns);
                    First;
                    while Eof = False do
                    begin
                      WriteRecord(VisibleColumns);
                      CalcFooterValues;
                      Next;
                    end;
                    for i := 0 to FooterRowCount - 1 do WriteFooter(VisibleColumns, i);
                  end;
              end;
            finally
              RestoreBook;
              EnableControls;
            end;
          end;
        end;
        WriteSuffix;
      finally
    //    FreeMem(FooterValues);
      end;
    end;
      

  5.   

    查看这个事件的源码SaveDBGridEhToExportFile
    跟踪调试 看看是在什么溢出
      

  6.   

    var  h:integer;       // ,k
    Excelid: OleVariant;                                //导出到excel,第一个uses要加上ComObj
    begin
    try
    Excelid:=CreateOLEObject('Excel.Application');
    except
    Application.MessageBox('Excel没有安装!', '提示信息', MB_OK+MB_ICONASTERISK+MB_DEFBUTTON1+MB_APPLMODAL);
    Exit;
    end;
    try
    Excelid.Visible:= True;
    Excelid.WorkBooks.Add;
    Excelid.WorkSheets[1].Cells[1,1].Value := '商品名称';
    Excelid.WorkSheets[1].Cells[1,2].Value := '单位';
    h:=2;
    data.Qpublic1.First;
    while not data.Qpublic1.Eof do
    begin
    Excelid.WorkSheets[1].Cells[h,1].Value := data.Qpublic1.FieldByName('X').AsString;
    Excelid.WorkSheets[1].Cells[h,2].Value := data.Qpublic1.FieldByName('Y).AsString;
    data.Qpublic1.Next;
    h:=h+1;
    end;
    Excelid.Quit;
    except
    Application.MessageBox('导入数据出错!请检查文件的格式是否正确!', '提示信息', MB_OK+MB_ICONASTERISK+MB_DEFBUTTON1+MB_APPLMODAL);
    end;
    end;看看这种行吗?