Need help to write spread (3.0) contents to a text file with column layout.

Posted by: bluefoxboy on 8 September 2017, 3:10 pm EST

  • Posted 8 September 2017, 3:10 pm EST

    I need to write spread contents with columns just like they are in the spread control. The 'savetabfile' method doesn't help much. Its not aligned when i export with that method. I need column width (that is maximum no. of characters that column in the spread can hold- not the pixels) to be the width of the 'column' in text file. How can I achieve this?. Something like the attachement

  • Replied 8 September 2017, 3:10 pm EST

    Hello,

    You may export to Excel to get the content as it is from SpreadSheet.

    Thanks,
    Deepak Sharma
  • Replied 8 September 2017, 3:10 pm EST

    Hi,

    Sorry, I think Deepak is confused about what you're trying to do. This forum is for Spread Windows Forms questions, but I think you are using Spread COM 3.0 instead? Are you using this SaveTabFile method?

    http://helpcentral.componentone.com/NetHelp/Spread8/WebSiteHelp/webframe.html#funct321.html

    That help context is for Spread COM version 8, but method has not changed since v3.

    Spread will write out the cells to the file with tab between column values and carriage return + line feed between each row.

    It's not possible to get the kind of output you describe using SaveTabFile, because there isn't any way to get the table formatting like that. You could export just the text and format it nicely to show like that, but without the parts like '|' between each column instead of tab and "\r\n----...----\r\n" between each row instead of "/r/n".

    To get the kind of layout you describe, you need to pad the cell values with spaces, and use a proportional font to view the file.

    You can use GetText and SetText methods to fix up the cell values, and use the ColWidth property to get the width of the column in units of average character width for the font, to calculate the number of spaces to pad before and after the value to get the layout you want (left/center/right) in each cell. Empty cells can just be padded with the column width.

    Spread COM 8 supports new methods that can output a formatted text file like you describe, ExportToTextFile, and ExportToTextFileU:

    http://helpcentral.componentone.com/NetHelp/Spread8/WebSiteHelp/webframe.html#funct180.html
    http://helpcentral.componentone.com/NetHelp/Spread8/WebSiteHelp/webframe.html#funct182.html

    Using one of those methods, you could specify custom delimiter strings to get the formatted output like you describe. You would still need to adjust the cell values to pad spaces for the cell contents, as described above, and you would need to upgrade to version 8. If you want to give it a try, the free 30 day trial version is posted here:

    http://www.componentone.com/Downloads/Download/?productID=524

    Hope that helps!

    If you have trouble making it work, please post a small sample and we can help further.

    Regards,
    -Sean
  • Replied 8 September 2017, 3:10 pm EST

    "use the ColWidth property to get the width of the column in units of average character width for the font"
    how can i get the character width of font?. Also I cannot upgrade right now
  • Replied 8 September 2017, 3:10 pm EST

    Hi,

    Sorry that wasn't clear, I mean you can use the ColWidth property and it will return a value that is already in units of average character width of the system font. The UnitType property specifies the units for ColWidth, please see here for more info:

    http://helpcentral.componentone.com/NetHelp/Spread8/WebSiteHelp/webframe.html#prop1027.html

    Regards,
    -Sean
  • Replied 8 September 2017, 3:10 pm EST

    Thank you, I did what you said.
    spread.UnitType = UnitTypeNormal. And Then i checked the column width using message box. It gives the width of the column (can be changed by re-sizing the column) not the maximum length of the characters that column can accommodate. I mean, the value which I can set at design time by right clicking column>edit> and setting the length text box. How can I get that value? during run time. I know I can set it in code but I will be using it for more spread sheets with different values

Need extra support?

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

Learn More

Forum Channels