--- grids.pas	2012-10-15 15:56:44.720450476 -0300
+++ /usr/lib/codetyphon/lazarus/lcl/grids.pas	2012-10-15 16:10:26.251317065 -0300
@@ -116,7 +116,8 @@
     soDesign,             // Save grid structure (col/row count and Options)
     soAttributes,         // Save grid attributes (Font,Brush,TextStyle)
     soContent,            // Save Grid Content (Text in stringgrid)
-    soPosition            // Save Grid cursor and selection position
+    soPosition,            // Save Grid cursor and selection position
+    soVisibleOnly
   );
   TSaveOptions = set of TGridSaveOptions;
 
@@ -10431,7 +10431,7 @@
 
 procedure TCustomStringGrid.SaveToCSVStream(AStream: TStream; ADelimiter: Char=','; WithHeader: boolean=true);
 var
-  i,StartRow: Integer;
+  i,j,StartRow: Integer;
   HeaderL, Lines: TStringList;
   C: TGridColumn;
 begin
@@ -10450,6 +10450,7 @@
               if c=nil then
                 HeaderL.Add(Cells[i, 0])
               else
+                if c.Visible or not (soVisibleOnly in SaveOptions) then
                 HeaderL.Add(c.Title.Caption);
             end;
             HeaderL.Delimiter:=ADelimiter;
@@ -10468,10 +10469,31 @@
     end else
       StartRow := FixedRows;
     for i:=StartRow to RowCount-1 do begin
+      if Columns.Enabled and (soVisibleOnly in SaveOptions) then begin
+        HeaderL := TStringList.Create;
+        try
+        for j := 1 to FixedCols do
+          HeaderL.Add('');
+        for j := 0 to ColCount-1 do begin
+          c := ColumnFromGridColumn(j);
+          if c=nil then Continue;
+          if c.Visible then
+            HeaderL.Add(Cells[j,i]);
+        end;
+        HeaderL.Delimiter:=ADelimiter;
+        HeaderL.StrictDelimiter := False; //force quoting of strings that contain whitespace or Delimiter
+        Lines.Add(HeaderL.DelimitedText); // Add the row in Lines
+        finally
+          HeaderL.Free;
+        end;
+      end
+      else
+      begin
       Rows[i].StrictDelimiter := False; //force quoting of strings that contain whitespace or Delimiter
       Rows[i].Delimiter:=ADelimiter;
       Lines.Add(Rows[i].DelimitedText);
     end;
+    end;
     Lines.SaveToStream(AStream);
   finally
     Lines.Free;
