How to set size of column of csv file?

后端 未结 3 1088
长情又很酷
长情又很酷 2021-01-11 13:53

I want to set the size of each column in csv file, I want to set the size of column against the field, I don\'t know where I can do the code of to set the size? Can anyone h

相关标签:
3条回答
  • 2021-01-11 14:24

    You can't... a CSV file has no formatting of any kind, including column size.

    If you want to control column widths, then you need to write the data to a format that does support columns widths, such as BIFF (.xls) or OfficeOpenXML (.xlsx) or OASIS Open Document Format (.ods) or Gnumeric or other spreadsheet.

    0 讨论(0)
  • 2021-01-11 14:28

    As I know, you cannot set a column size in CSV because there is absolutely no information about the presentation layout. CSV is Coma Separated Value.

    The best behaviour for you application that will open your file is to set the column width to fit the data.

    If you want to manage your presentation layout, you should instead generate a html content that could be opened with Excel (in example). In such a content, you will be able to set some attributes like width="400"...

    0 讨论(0)
  • 2021-01-11 14:35

    There is no way to do this.
    CSV stands for coma separated values:

    A comma-separated values (CSV) file stores tabular data (numbers and text) in plain-text form. Plain text means that the file is a sequence of characters, with no data that has to be interpreted instead, as binary numbers. A CSV file consists of any number of records, separated by line breaks of some kind; each record consists of fields, separated by some other character or string, most commonly a literal comma or tab. Usually, all records have an identical sequence of fields.

    Short and clear definition.
    CSV is too primitive for this.
    Did you ever try to open CSV file with usual text editor?
    You need XLS for this case.

    0 讨论(0)
提交回复
热议问题