Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Creating a spreadsheet in obj-c

erikdudeerikdude NorwayPosts: 41New Users @
Hello!

I'm working on a feature in my app whereas I need to create a spreadsheet file that can be read by the majority of spreadsheet programs, like MS Excel or OpenOffice.

I've worked with *.CSV files so far, but it's very hard making it a "universal" file that every reader can open without going through a maze of menus first.

What's the best format I can write to using obj-c which is also quite simple to create?

Thank you!
Erik

Replies

  • dev666999dev666999 Posts: 3,558New Users @ @ @ @ @
    Give your file the .xls extension, and Excel and OpenOffice will open it automatically.
  • erikdudeerikdude NorwayPosts: 41New Users @
    dev666999 wrote: »
    Give your file the .xls extension, and Excel and OpenOffice will open it automatically.

    With semicolon-separated values inside?
  • dev666999dev666999 Posts: 3,558New Users @ @ @ @ @
    No, just a standard excel file with columns rows etc...

    Adding an .xls extension will have it open that way.
  • erikdudeerikdude NorwayPosts: 41New Users @
    dev666999 wrote: »
    No, just a standard excel file with columns rows etc...

    Adding an .xls extension will have it open that way.

    Yeah, but the problem is how to create such a file in objective-c
  • dev666999dev666999 Posts: 3,558New Users @ @ @ @ @
    edited August 2015
    Create the file as a .txt file. Then change the extension to .xls. That works for me. I just did it with an Apple Daily Sales report that has the .txt extension.
  • erikdudeerikdude NorwayPosts: 41New Users @
    edited August 2015
    dev666999 wrote: »
    The way to do it is to create a file with a .txt extension. That should open up fine in Excel and OpenOffice.

    Playing around with this. Apple's daily sales reports are in the .txt format and the open directly into Excel. Open one up and see what the delimiter is.

    Strange... If I open up the Sales and Trends module iTunes Connect, and download as CSV, it opens straight into excel, but all the data is in one column. What download button did you use?
  • dev666999dev666999 Posts: 3,558New Users @ @ @ @ @
    edited August 2015
    See my corrected reply to you above. Sorry about that... I was testing it too, and got that same result. Create a .txt file, and change it to .xls

    The .txt file is should be tab delimited.

    That should give you what you want.
  • erikdudeerikdude NorwayPosts: 41New Users @
    dev666999 wrote: »
    See my corrected reply to you above. Sorry about that... I was testing it too, and got that same result. Create a .txt file, and change it to .xls

    The .txt file is should be tab delimited.

    That should give you what you want.

    I'll be sure to try it, but I can't find the file to download from iTunes Connect. Went into Sales and Trends but I can't find the document you mentioned
  • erikdudeerikdude NorwayPosts: 41New Users @
    erikdude wrote: »
    dev666999 wrote: »
    See my corrected reply to you above. Sorry about that... I was testing it too, and got that same result. Create a .txt file, and change it to .xls

    The .txt file is should be tab delimited.

    That should give you what you want.

    I'll be sure to try it, but I can't find the file to download from iTunes Connect. Went into Sales and Trends but I can't find the document you mentioned

    Nevermind, think I found it now
  • BrianSlickBrianSlick Treadmill Desk Ninja Posts: 10,689Tutorial Authors, Registered Users @ @ @ @ @ @ @ @
    Depending on the nature of your data, delimited formats can be a problem if your contents would ever naturally contain the delimiting character(s). From your other thread, you're struggling with commas because commas might appear in your data (ex "123,45" where the US would do that as "123.45"). If there are a lot of words in your data, and the user can do some formatting, then tabs could potentially be a problem as well.

    That's a key reason that pretty much nobody uses CSV as an internal file format. You need some way to encapsulate each piece of data so that it doesn't interfere with the formatting. This suggests something like XML, which is what Microsoft converted their format to several years ago.

    This was my first hit with a Google search for universal spreadsheet formats. Might be worth further research:

    https://en.wikipedia.org/wiki/OpenDocument

    I also think that Microsoft's .xlsx format is technically open. Anybody who wants to even pretend to be a serious spreadsheet player is going to be able to handle Microsoft's file formats. So you've got at least a couple different options to pursue that aren't reliant on delimiters.
    Professional iOS App Development. Available for hire.
    BriTer Ideas LLC - WWW | Facebook | Twitter | LinkedIn

    BTIKit | BTICoreDataKit | SlickShopper 2 | Leave a PayPal donation
  • erikdudeerikdude NorwayPosts: 41New Users @
    edited August 2015
    BrianSlick wrote: »
    Depending on the nature of your data, delimited formats can be a problem if your contents would ever naturally contain the delimiting character(s). From your other thread, you're struggling with commas because commas might appear in your data (ex "123,45" where the US would do that as "123.45"). If there are a lot of words in your data, and the user can do some formatting, then tabs could potentially be a problem as well.

    That's a key reason that pretty much nobody uses CSV as an internal file format. You need some way to encapsulate each piece of data so that it doesn't interfere with the formatting. This suggests something like XML, which is what Microsoft converted their format to several years ago.

    This was my first hit with a Google search for universal spreadsheet formats. Might be worth further research:

    https://en.wikipedia.org/wiki/OpenDocument

    I also think that Microsoft's .xlsx format is technically open. Anybody who wants to even pretend to be a serious spreadsheet player is going to be able to handle Microsoft's file formats. So you've got at least a couple different options to pursue that aren't reliant on delimiters.

    The data displayed is quite "strict" and only displays key information, so I can have it exclude delimiting characters to avoid confusion. Problem with CSV is how it's read. A semicolon/comma CSV file would open with mail on my iPhone just fine, while Excel here would only accept semicolon. But perhaps only comma will work where you are located for instance. I'll do some research into OpenDocument and how I can write to it using obj-c.
  • BrianSlickBrianSlick Treadmill Desk Ninja Posts: 10,689Tutorial Authors, Registered Users @ @ @ @ @ @ @ @
    I know for a fact that Excel allows you to specify what to use as a delimiter. In some situations it may guess for you, and/or handle some delimiters a bit more automatically than others, but I assure you that Excel can handle much more than a semicolon. It may be a difference of what happens with "Open File" vs "Import File" (I haven't looked at Excel in a long time to know what the current UI is), but I promise that Excel can take just about anything you'd throw at it.
    Professional iOS App Development. Available for hire.
    BriTer Ideas LLC - WWW | Facebook | Twitter | LinkedIn

    BTIKit | BTICoreDataKit | SlickShopper 2 | Leave a PayPal donation
  • erikdudeerikdude NorwayPosts: 41New Users @
    BrianSlick wrote: »
    I know for a fact that Excel allows you to specify what to use as a delimiter. In some situations it may guess for you, and/or handle some delimiters a bit more automatically than others, but I assure you that Excel can handle much more than a semicolon. It may be a difference of what happens with "Open File" vs "Import File" (I haven't looked at Excel in a long time to know what the current UI is), but I promise that Excel can take just about anything you'd throw at it.

    Yeah, no doubt. I just need it so that you can double click a file or select file->open. What would you do in such a "situation"?
  • BrianSlickBrianSlick Treadmill Desk Ninja Posts: 10,689Tutorial Authors, Registered Users @ @ @ @ @ @ @ @
    Generate a .xlsx file format, don't rely on delimiters.

    Probably won't be too hard to figure out. Set up a spreadsheet that looks the way you want. Save. Open that file in a text editor. Then write code to mimic what you see.
    Professional iOS App Development. Available for hire.
    BriTer Ideas LLC - WWW | Facebook | Twitter | LinkedIn

    BTIKit | BTICoreDataKit | SlickShopper 2 | Leave a PayPal donation
  • erikdudeerikdude NorwayPosts: 41New Users @
    BrianSlick wrote: »
    Generate a .xlsx file format, don't rely on delimiters.

    Probably won't be too hard to figure out. Set up a spreadsheet that looks the way you want. Save. Open that file in a text editor. Then write code to mimic what you see.

    Looking into that now. Really hard imo - can't find a way to do it. Opening up a .xlsx file in TextEdit creates tons of weird symbols, so I made it a zip file and decompressed it - but there's a lot of folders and files within there that I have no idea on how to mimic properly.
Sign In or Register to comment.