Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Writing to a CSV file - can we add colour to a cell?
QtWS25 Last Chance

Writing to a CSV file - can we add colour to a cell?

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 5 Posters 787 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aftershocker1
    wrote on 8 Sept 2021, 07:08 last edited by
    #1

    Hello,

    I am outputting data to a CSV file. The data is writing correctly and saving where I want it to save to. I was wondering if there was any way to add colour to a cell? For example if a bool is true the the cell would be green, false it would be red? I think as it is just a text stream that I will be unable to do this but thought it would be worth asking the forum. Thought process is that as opposed to having extra cells with pass/fail result if the numerical data is colour code depending on the result it will save the CSV being 100 cells long and be more readable for the user.

    Thanks

    J 1 Reply Last reply 8 Sept 2021, 07:47
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on 8 Sept 2021, 07:36 last edited by
      #2

      You want a plain text file to appear in colour when opened in what?

      A 1 Reply Last reply 8 Sept 2021, 08:44
      2
      • A aftershocker1
        8 Sept 2021, 07:08

        Hello,

        I am outputting data to a CSV file. The data is writing correctly and saving where I want it to save to. I was wondering if there was any way to add colour to a cell? For example if a bool is true the the cell would be green, false it would be red? I think as it is just a text stream that I will be unable to do this but thought it would be worth asking the forum. Thought process is that as opposed to having extra cells with pass/fail result if the numerical data is colour code depending on the result it will save the CSV being 100 cells long and be more readable for the user.

        Thanks

        J Online
        J Online
        JonB
        wrote on 8 Sept 2021, 07:47 last edited by
        #3

        @aftershocker1
        A CSV file is just for exporting the data. No other information (other than an optional column header row).

        A 1 Reply Last reply 8 Sept 2021, 08:09
        1
        • J JonB
          8 Sept 2021, 07:47

          @aftershocker1
          A CSV file is just for exporting the data. No other information (other than an optional column header row).

          A Offline
          A Offline
          aftershocker1
          wrote on 8 Sept 2021, 08:09 last edited by
          #4

          @JonB Thanks. That's what I thought I just wondered if Qt had something built it that allowed it to be displayed in a different format in a spreadsheet.

          Thanks for your help

          M 1 Reply Last reply 8 Sept 2021, 08:43
          0
          • A aftershocker1
            8 Sept 2021, 08:09

            @JonB Thanks. That's what I thought I just wondered if Qt had something built it that allowed it to be displayed in a different format in a spreadsheet.

            Thanks for your help

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 8 Sept 2021, 08:43 last edited by
            #5

            @aftershocker1

            Hi
            Well excel can import a HTML table so it is possible.
            Just not with the CSV format.

            A 1 Reply Last reply 8 Sept 2021, 08:55
            0
            • C ChrisW67
              8 Sept 2021, 07:36

              You want a plain text file to appear in colour when opened in what?

              A Offline
              A Offline
              aftershocker1
              wrote on 8 Sept 2021, 08:44 last edited by
              #6

              @ChrisW67 I just wondered if when opened in a spreadsheet if there could be some basic formatting of the cells. I am aware that that isn't possible

              J 1 Reply Last reply 8 Sept 2021, 08:48
              0
              • A aftershocker1
                8 Sept 2021, 08:44

                @ChrisW67 I just wondered if when opened in a spreadsheet if there could be some basic formatting of the cells. I am aware that that isn't possible

                J Offline
                J Offline
                JKSH
                Moderators
                wrote on 8 Sept 2021, 08:48 last edited by
                #7

                @aftershocker1 said in Writing to a CSV file - can we add colour to a cell?:

                I just wondered if when opened in a spreadsheet if there could be some basic formatting of the cells.

                Opened with what?

                If you are writing your own CSV viewer, you can set the view's cell's colour. Note that the formatting occurs in the viewer, not in the CSV file itself.

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                1 Reply Last reply
                0
                • M mrjj
                  8 Sept 2021, 08:43

                  @aftershocker1

                  Hi
                  Well excel can import a HTML table so it is possible.
                  Just not with the CSV format.

                  A Offline
                  A Offline
                  aftershocker1
                  wrote on 8 Sept 2021, 08:55 last edited by
                  #8

                  @mrjj Sound like it could be interesting in the future. For this is just basic data for engineers to analyse so doesn't need to look overly fancy. In my head I thought it would have been good to have a cell green if true/pass but I will just put the reading in a cell then the next cell showing the result as a bool.

                  M J 2 Replies Last reply 8 Sept 2021, 08:59
                  0
                  • A aftershocker1
                    8 Sept 2021, 08:55

                    @mrjj Sound like it could be interesting in the future. For this is just basic data for engineers to analyse so doesn't need to look overly fancy. In my head I thought it would have been good to have a cell green if true/pass but I will just put the reading in a cell then the next cell showing the result as a bool.

                    M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 8 Sept 2021, 08:59 last edited by
                    #9

                    @aftershocker1

                    Well if only to mark rows for ok/fail then i think using a column will also work fine.
                    Besides, the engineers can most likely apply conditional formatting in Excel and
                    color it based on value if they want :)

                    1 Reply Last reply
                    1
                    • A aftershocker1
                      8 Sept 2021, 08:55

                      @mrjj Sound like it could be interesting in the future. For this is just basic data for engineers to analyse so doesn't need to look overly fancy. In my head I thought it would have been good to have a cell green if true/pass but I will just put the reading in a cell then the next cell showing the result as a bool.

                      J Online
                      J Online
                      JonB
                      wrote on 8 Sept 2021, 10:21 last edited by
                      #10

                      @aftershocker1
                      To be clear: if you want formatting (like color etc.) you can't just export as CSV, you have to export as an actual Excel file. Either an XLSX writer library, or if you are on Windows QAxObject. It's a lot more work than a plain CSV file!

                      A 1 Reply Last reply 8 Sept 2021, 10:51
                      0
                      • J JonB
                        8 Sept 2021, 10:21

                        @aftershocker1
                        To be clear: if you want formatting (like color etc.) you can't just export as CSV, you have to export as an actual Excel file. Either an XLSX writer library, or if you are on Windows QAxObject. It's a lot more work than a plain CSV file!

                        A Offline
                        A Offline
                        aftershocker1
                        wrote on 8 Sept 2021, 10:51 last edited by
                        #11

                        @JonB Thanks. It is not going to be worth the hassle this time but all good info for the future.

                        1 Reply Last reply
                        0

                        2/11

                        8 Sept 2021, 07:36

                        topic:navigator.unread, 9
                        • Login

                        • Login or register to search.
                        2 out of 11
                        • First post
                          2/11
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved