We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Export to various Formats

Is it possible to export the contents of the grid to few formats like Excel, CSV and TXT. One way is that I parse thru the grid and write the file in desired format and save it on the disk but is there any inbuilt feature that provides such support. Regards Ashish

4 Replies

AD Administrator Syncfusion Team May 12, 2003 09:16 AM UTC

Currently, you can import/export data in delimited text files such as CSV or TSV. You can find code snippets in the 3rd or 4th entry of this forum thread. http://www.syncfusion.com/forums/message.asp?MessageID=3292 We will support reading and writing of BIFF files(excel) in an upcoming release. I do not know a projected release date yet force this support.


GR Greg May 11, 2004 06:40 PM UTC

That was a very nice example of CSV exporting, but unfortunately it is not complete enough for real use. It fails to achieve my goals on two parts, making it unlikely to write and read what it has written: 1) When a cell contains the cell delimeter character (comma for U.S.), the entire cell should be surrounded by double quotes, and (related) 2) If cell contents contain double quotes, then double quotes need to surround the cell contents, and all pre-existing double quotes doubled. Thanks for the attempt. -Greg


AD Administrator Syncfusion Team May 11, 2004 10:17 PM UTC

If you own the source code, you can copy and modify the code used in our CopyTextToBuffer and PasteTextFromBuffer methods to use the extra quotes you need for your data. Or, maybe another option would be to use a different delimiter that avoids the problem with the comma, (maybe a tab). this.gridControl1.Model.TextDataExchange.ExportTabDelim = "\t"; this.gridControl1.Model.TextDataExchange.ImportTabDelim = "\t";


GR Greg May 11, 2004 11:00 PM UTC

Thanks, Clay. For anyone wanting logic to format cell text for CSV output that works for internal commas and quotes: for each row in range clear StringBuilder line for each column in range get string celltext // replace quotes with doubled quotes celltext = cell.Text.Replace("\"","\"\""); // if any quotes or comma (separator), // then start and end with a quote if (-1 != celltext.IndexOfAny(",\"".ToCharArray())) celltext = "\"" + celltext + "\""; line.Append(celltext); // append that cell line.Append(",");// column separator (comma or semicolon) } // each column // compress out trailing commas str = line.ToString(); str = str.TrimEnd(","); WriteLine(str); // write that row } // each row Worked for me. Cheers, Greg

Loader.
Live Chat Icon For mobile
Up arrow icon