Find the answer to your Linux question:
Results 1 to 7 of 7
Hi All, I am using shell scripting to write my data into a .csv file. But I am not getting any method to write into a different worksheet in the ...
  1. #1
    Just Joined!
    Join Date
    May 2008
    Posts
    9

    Question Writing into a .csv file

    Hi All,

    I am using shell scripting to write my data into a .csv file. But I am not getting any method to write into a different worksheet in the same .csv file. So I create a different csv file itself to write all my data and then combine those csv files into a single file.

    For ex: For each data1, data2 currently the data is written into file1.csv, file2.csv. Instead I want to write all the data into a single file.csv but in different worksheets.

    My queries are
    1. Can I use shell scripting to achieve this?
    2. If yes then can u please help me a bit to write the script?
    3. If shell scripting cannot be used then how to achieve this? Any suggested reading?

    Thank You all for taking time in reading this query. An extra thanks for all those who are suggesting me an idea

    Regards,
    Santosh

  2. #2
    Just Joined!
    Join Date
    Nov 2008
    Posts
    11
    You asked this same question last week, which I responded to. Since I'm guessing you didn't like the suggestion of using Python, I'll simply remind you of this - a .csv file does not contain worksheets.

    You need to be dealing with .xls files NOT .csv files.

  3. #3
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    If I were doing this, I'd have Excel write to a csv file to test Rinkwraith's statement that worksheets cannot be contained in csv files. If Excel creates separate files (or exhibits some other behavior) for each worksheet, then it would seem improbable that it would do what you appear to want for importing data.

    Googling for the words excel format csv worksheet brings up a number of hits which could be investigated.

    The page at Microsoft Excel - Wikipedia, the free encyclopedia suggests that Rinkwraith is likely correct about xls, which, for recent versions of Excel means XML-based -- a format which would not be easy (for me, anyway) to create with a shell script. That's probably the reason for the Python suggestion, although there may be other languages that have some support for reading and writing such files. For example, a perl module: libspreadsheet-writeexcel-perl - create Excel spreadsheets .

    If your goal is get data into Excel, the article suggests that there are other legacy formats, e.g. SYLK, DIF, that Excel can read.

    Interestingly, there is a standard for csv files: Comma-separated values - Wikipedia, the free encyclopedia

    If all else fails, I'd try to create my own csv-like text format, and use Excel facilities (e.g. macros) to create the separate worksheets ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  4. #4
    Just Joined!
    Join Date
    May 2008
    Posts
    9

    Smile Writing into a .csv file

    Hi Rinkwraith,

    Yes you are right. A .csv file does not have a worksheet. But when you open this .csv file with spreadsheet application it provides me all the options just like a .xls file. So I thought if I can somehow program it to write into a seperate worksheet when I open this .csv using this spreadsheet application.

    Let me know if you have any suggestions for this.

    Regards,
    Santosh

  5. #5
    Just Joined!
    Join Date
    May 2008
    Posts
    9
    Quote Originally Posted by drl View Post
    Hi.

    If I were doing this, I'd have Excel write to a csv file to test Rinkwraith's statement that worksheets cannot be contained in csv files. If Excel creates separate files (or exhibits some other behavior) for each worksheet, then it would seem improbable that it would do what you appear to want for importing data.

    Googling for the words excel format csv worksheet brings up a number of hits which could be investigated.

    The page at Microsoft Excel - Wikipedia, the free encyclopedia suggests that Rinkwraith is likely correct about xls, which, for recent versions of Excel means XML-based -- a format which would not be easy (for me, anyway) to create with a shell script. That's probably the reason for the Python suggestion, although there may be other languages that have some support for reading and writing such files. For example, a perl module: libspreadsheet-writeexcel-perl - create Excel spreadsheets .

    If your goal is get data into Excel, the article suggests that there are other legacy formats, e.g. SYLK, DIF, that Excel can read.

    Interestingly, there is a standard for csv files: Comma-separated values - Wikipedia, the free encyclopedia

    If all else fails, I'd try to create my own csv-like text format, and use Excel facilities (e.g. macros) to create the separate worksheets ... cheers, drl
    Thanks a lot for your suggestions. I will check with the handles that you have provided me.

  6. #6
    Just Joined!
    Join Date
    Nov 2008
    Posts
    11
    Excel and other spreadsheets applications tend to open .csv files by creating a new spreadsheet in memory (e.g. .xls) and importing the .csv into the first worksheet. If you add data to a second sheet and try to Save As csv you'll get this message (e.g. from Excel):

    "The selected file type does not suport workbooks that contain multiple sheets."

    I'd honestly look at learning Python and using the pyxlwriter lib.

    Python is really really easy to learn - in a couple of hours max you'd be ready to code this project. And once you've learnt it, its a cool alternative to the shell for doing these kinds of programming jobs.

  7. #7
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.
    Quote Originally Posted by Rinkwraith View Post
    Excel and other spreadsheets applications tend to open .csv files by creating a new spreadsheet in memory (e.g. .xls) and importing the .csv into the first worksheet. If you add data to a second sheet and try to Save As csv you'll get this message (e.g. from Excel):

    "The selected file type does not suport workbooks that contain multiple sheets."
    ...
    OK, good to know; thanks for doing the leg-work on that.

    Perhaps if the working environment and Excel-like application allows it, one might be able to do some scripting, like:
    Code:
    tell application "Microsoft Word"
      quit
    end tell
    which is from the article AppleScript - Wikipedia, the free encyclopedia . I generally don't use applications like Office-things, so I cannot speak with any authority on specifics ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...