export to a csv file

Posted by: ashapournami on 8 September 2017, 1:26 pm EST

  • Posted 8 September 2017, 1:26 pm EST

    Hi


     I am doing an export function. But I need the file exported to be saved as a csv file. The file gets saved as csv but the problem is that the sheet name remains as Sheet1 and not the name of the file. So when I try to import this file and fill it in a datatable incorrect text is coming in the datatable.How can I sort this issue


    Thanks


    Asha

  • Replied 8 September 2017, 1:26 pm EST

    Hi Scott


    Csv file will have a single sheet and the sheetname and file name will be same. Right?


    But when I do an export and save the file as csv the sheetname is coming as Sheet 1


     I am using the below code.


    DialogResult dlgRes;


    SaveFileDialog fdgSave = new SaveFileDialog();


    fdgSave.Filter = "Microsoft Excel files (*.xls)|*.xls|CSV (comma delimited)(*.csv)|*.csv";


    fdgSave.Title = "Export Spread Details to Excel";


    dlgRes = fdgSave.ShowDialog();


    if (dlgRes == DialogResult.OK)


    {


    Cursor.Current = Cursors.WaitCursor;


    strFileName = fdgSave.FileName;


    foreach (FarPoint.Win.Spread.SheetView svData in fpsSpread.Sheets)


    {


    svData.Protect = false;


    svData.PrintInfo.Orientation = FarPoint.Win.Spread.PrintOrientation.Landscape;


    }


    fpsSpread.SaveExcel(strFileName, FarPoint.Win.Spread.Model.IncludeHeaders.ColumnHeadersCustomOnly);


    foreach (FarPoint.Win.Spread.SheetView svData in fpsSpread.Sheets)


    {


    svData.Protect = true;


    }


     


    }


     Thanks


    Asha

  • Replied 8 September 2017, 1:26 pm EST

    Hello,


    Using the SaveExcel method of Spread, the file is exported as BIFF8. The SheetName(s) exported would be the sheetname(s) you set up in Spread. Even if you save the file with a CSV extension, it is still not a comma delimited file but rather a BIFF* formatted file. If you export to Excel and then use the Save As menu in Excel to save the BIFF* formatted file to CSV, then the filename you provide will be the SheetName displayed.

  • Replied 8 September 2017, 1:26 pm EST

    So, Is there a way by which I can save the spread as a csv file


     Thanks


    Asha

  • Replied 8 September 2017, 1:26 pm EST

    Asha,


    SheetNames are not saved with comma delimited files. How are you expecting the SheetName to be preserved in this type of file? Could you export the spreadsheet to Excel (BIFF8 format) instead of CSV?

  • Replied 8 September 2017, 1:26 pm EST

    Asha,


    If you want to save directly to a comma delimited file, you need to use the SaveTextFile method of the SheetView you want to save.

  • Replied 8 September 2017, 1:26 pm EST

    Thanks a lot for the reply Scott.


    Thanks


    Asha

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels