TdxTreeList如何能向TdxDBGrid那样导出数据(100分)

  • 主题发起人 主题发起人 snowmao
  • 开始时间 开始时间
S

snowmao

Unregistered / Unconfirmed
GUEST, unregistred user!
TdxTreeList如何能向TdxDBGrid那样导出数据:<br>TdxDBGrid有SaveToXLS等功能,而TdxTreeList没有,怎么办?
 
自己按照tree的样子生成一个grid,然后用grid的savetoxls就可以<br>只是倒不出来树状,不过可以加空格模拟树,如果要到处树状的话,估计要自己写了
 
有例子吗
 
try<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Excel := CreateOleObject('Excel.Application');<br>&nbsp; &nbsp; &nbsp; except<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; on e: Exception do begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MessageBox(GetActiveWindow, '导出失败,请先安装电子表格Microsoft Excel', '警告提示', MB_ICONWARNING or MB_OK);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Excel := null;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WorkBook := Excel.Application.WorkBooks.Add;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WorkSheet := WorkBook.WorkSheets[1];<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //列<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for c := 0 to VisibleColumnCount - 1 do begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WorkSheet.Columns[c + 1].NumberFormat := '@';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WorkSheet.Cells[1, c + 1].Value := VisibleColumns[c].Caption.Text;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //行<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for r := 0 to Nodes.Count - 1 do begin &nbsp;//改变下遍历方式<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for c := 0 to VisibleColumnCount - 1 do begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WorkSheet.Cells[r + 2, c + 1].Value := Nodes[r].Texts[c];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if WorkBook.SaveAs(fileName) then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MessageBox(GetActiveWindow, pchar('成功导出到文件' + fileName), '提示', MB_ICONINFORMATION or MB_OK);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; except<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; on e: Exception do begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MessageBox(GetActiveWindow, '保存失败,请检查文件是否正在使用', '提示', MB_ICONWARNING or MB_OK);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exit;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; except<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; on e: Exception do begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MessageBox(GetActiveWindow, PChar(e.Message), '警告', MB_ICONWARNING or MB_OK);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WorkBook.Saved := True;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WorkBook := null;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Excel.Quit;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Excel := null;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; &nbsp; WorkBook.Saved := True;<br>&nbsp; &nbsp; &nbsp; WorkBook := null;<br>&nbsp; &nbsp; &nbsp; Excel.Quit;<br>&nbsp; &nbsp; &nbsp; Excel := null;
 
后退
顶部