Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. using CDatabase writing into excel files

using CDatabase writing into excel files

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
7 Posts 3 Posters 0 Views 1 Watching
  • 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    hello. i am having a small problem. from code project only i have down loaded a code. that uses an object of CDatabase, the n calls its oopen function with microsoft excel driver. after thatn writing in to a excel file using .executesql(" insert into demo4 vales(.....)) function. like that. the result excel file is coming but at the beginning of each cell one ' is getting added to the data content( eg if adams is the data, 'adams is coming in excel , it is appearing as adams only but if u double click on the cell it is giving contents as 'adam. why is that so . is there any way to make it not come in the resultant excel files ? please tell me. -- modified at 9:54 Monday 26th September, 2005

    D 1 Reply Last reply
    0
    • L Lost User

      hello. i am having a small problem. from code project only i have down loaded a code. that uses an object of CDatabase, the n calls its oopen function with microsoft excel driver. after thatn writing in to a excel file using .executesql(" insert into demo4 vales(.....)) function. like that. the result excel file is coming but at the beginning of each cell one ' is getting added to the data content( eg if adams is the data, 'adams is coming in excel , it is appearing as adams only but if u double click on the cell it is giving contents as 'adam. why is that so . is there any way to make it not come in the resultant excel files ? please tell me. -- modified at 9:54 Monday 26th September, 2005

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Show the code snippet that adds the values to the cells.


      "One must learn from the bite of the fire to leave it alone." - Native American Proverb

      T 1 Reply Last reply
      0
      • D David Crow

        Show the code snippet that adds the values to the cells.


        "One must learn from the bite of the fire to leave it alone." - Native American Proverb

        T Offline
        T Offline
        tejaswi teja
        wrote on last edited by
        #3

        sSql.Format("DRIVER={%s};DSN='';FIRSTROWHASNAMES=1;READONLY=FALSE;CREATE_DB=\"%s\";DBQ=%s", sDriver,gsExcelFileName,gsExcelFileName); if( database.OpenEx(sSql,CDatabase::noOdbcDialog) ) { //Create table structure sSql = "Create Table MIDs ( ECMName TEXT,MID_Hex TEXT,MID_Dec TEXT,GroupBroadcast TEXT,ME_Number TEXT,AlarmLevel TEXT,SpecialWarning TEXT,AbuseType TEXT,ParameterName TEXT,Status TEXT,Instruction TEXT,MID TEXT,CID TEXT,DeleteCIDs TEXT,Display TEXT,Log TEXT,ServiceLamp TEXT,Telemetry TEXT,EventRecorder TEXT,ESET TEXT,Start TEXT,Actuate TEXT,Deactuate TEXT,Acknowledge TEXT,ServiceLight TEXT )"; //HistogramID number, HIstogramFormula TEXT)"; database.ExecuteSQL(sSql); . . . . . // The below is all sqlstatement how it is constructed. ValuesString.Format("'%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s'",ControlValueArray[44][1],MIDHexValue,ControlValueArray[43][1],ControlValueArray[2][1],ControlValueArray[3][1],AlaramLevel,ControlValueArray[38][1],ControlValueArray[39][1],ControlValueArray[44][1],ControlValueArray[41][1],ControlValueArray[42][1],ControlValueArray[43][1],ControlValueArray[4][1],DeleteCIDs,ControlValueArray[32][1],ControlValueArray[31][1],ControlValueArray[30][1],ControlValueArray[29][1],ControlValueArray[33][1],ControlValueArray[28][1],"N/A",ControlValueArray[15][1],ControlValueArray[16][1],ControlValueArray[17][1],ControlValueArray[18][1] ); sSql = "INSERT INTO MIDs(ECMName ,MID_Hex ,MID_Dec ,GroupBroadcast ,ME_Number ,AlarmLevel ,SpecialWarning ,AbuseType ,ParameterName ,Status ,Instruction ,MID ,CID ,DeleteCIDs ,Display ,Log ,ServiceLamp ,Telemetry ,EventRecorder ,ESET ,Start ,Actuate ,Deactuate ,Acknowledge ,ServiceLight ) VALUES ("+ ValuesString+ ")"; database.ExecuteSQL(sSql); database.Close(); Like this it is adding to excel.

        D 1 Reply Last reply
        0
        • T tejaswi teja

          sSql.Format("DRIVER={%s};DSN='';FIRSTROWHASNAMES=1;READONLY=FALSE;CREATE_DB=\"%s\";DBQ=%s", sDriver,gsExcelFileName,gsExcelFileName); if( database.OpenEx(sSql,CDatabase::noOdbcDialog) ) { //Create table structure sSql = "Create Table MIDs ( ECMName TEXT,MID_Hex TEXT,MID_Dec TEXT,GroupBroadcast TEXT,ME_Number TEXT,AlarmLevel TEXT,SpecialWarning TEXT,AbuseType TEXT,ParameterName TEXT,Status TEXT,Instruction TEXT,MID TEXT,CID TEXT,DeleteCIDs TEXT,Display TEXT,Log TEXT,ServiceLamp TEXT,Telemetry TEXT,EventRecorder TEXT,ESET TEXT,Start TEXT,Actuate TEXT,Deactuate TEXT,Acknowledge TEXT,ServiceLight TEXT )"; //HistogramID number, HIstogramFormula TEXT)"; database.ExecuteSQL(sSql); . . . . . // The below is all sqlstatement how it is constructed. ValuesString.Format("'%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s'",ControlValueArray[44][1],MIDHexValue,ControlValueArray[43][1],ControlValueArray[2][1],ControlValueArray[3][1],AlaramLevel,ControlValueArray[38][1],ControlValueArray[39][1],ControlValueArray[44][1],ControlValueArray[41][1],ControlValueArray[42][1],ControlValueArray[43][1],ControlValueArray[4][1],DeleteCIDs,ControlValueArray[32][1],ControlValueArray[31][1],ControlValueArray[30][1],ControlValueArray[29][1],ControlValueArray[33][1],ControlValueArray[28][1],"N/A",ControlValueArray[15][1],ControlValueArray[16][1],ControlValueArray[17][1],ControlValueArray[18][1] ); sSql = "INSERT INTO MIDs(ECMName ,MID_Hex ,MID_Dec ,GroupBroadcast ,ME_Number ,AlarmLevel ,SpecialWarning ,AbuseType ,ParameterName ,Status ,Instruction ,MID ,CID ,DeleteCIDs ,Display ,Log ,ServiceLamp ,Telemetry ,EventRecorder ,ESET ,Start ,Actuate ,Deactuate ,Acknowledge ,ServiceLight ) VALUES ("+ ValuesString+ ")"; database.ExecuteSQL(sSql); database.Close(); Like this it is adding to excel.

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Did you look at how ValuesString is being constructed? The cause of your ' problem is right there? :confused:


          "One must learn from the bite of the fire to leave it alone." - Native American Proverb

          T 1 Reply Last reply
          0
          • D David Crow

            Did you look at how ValuesString is being constructed? The cause of your ' problem is right there? :confused:


            "One must learn from the bite of the fire to leave it alone." - Native American Proverb

            T Offline
            T Offline
            tejaswi teja
            wrote on last edited by
            #5

            i did not get whatu are telling. actually all those values in the values string are text values. so them i have written as 'content' . because in the sql sltatement they should be given as insert into tablename values('text1','text2',number e.t.c); so have used format('%s', variablevalue) for forming ValuesString . just now have seen while trying to print into number fields it is giving normally but while printing text values , the value of the cell is shown as normally only but preceded by a ' symbol when double clicking on the cell. after dblclk on cell the value is like '1234 for text, copy cell contents and paste it elsewhere in note pad they appearing like: ECMName MID_Hex peninsula 5678

            D 1 Reply Last reply
            0
            • T tejaswi teja

              i did not get whatu are telling. actually all those values in the values string are text values. so them i have written as 'content' . because in the sql sltatement they should be given as insert into tablename values('text1','text2',number e.t.c); so have used format('%s', variablevalue) for forming ValuesString . just now have seen while trying to print into number fields it is giving normally but while printing text values , the value of the cell is shown as normally only but preceded by a ' symbol when double clicking on the cell. after dblclk on cell the value is like '1234 for text, copy cell contents and paste it elsewhere in note pad they appearing like: ECMName MID_Hex peninsula 5678

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              tejaswi_teja wrote: i did not get whatu are telling. actually all those values in the values string are text values. so them i have written as 'content' . because in the sql sltatement they should be given as insert into tablename values('text1','text2',number e.t.c); so have used format('%s', variablevalue) for forming ValuesString . I understand now. tejaswi_teja wrote: just now have seen while trying to print into number fields it is giving normally but while printing text values , the value of the cell is shown as normally only but preceded by a ' symbol when double clicking on the cell. after dblclk on cell the value is like '1234 for text, copy cell contents and paste it elsewhere in note pad they appearing like: ECMName MID_Hex peninsula 5678 Since the single quote marks in each cell are for display purposes only (they tell Excel to treat the text exactly as you have entered it), and does not affect printing or pasting to other applications, is there any harm in leaving them there?


              "One must learn from the bite of the fire to leave it alone." - Native American Proverb

              T 1 Reply Last reply
              0
              • D David Crow

                tejaswi_teja wrote: i did not get whatu are telling. actually all those values in the values string are text values. so them i have written as 'content' . because in the sql sltatement they should be given as insert into tablename values('text1','text2',number e.t.c); so have used format('%s', variablevalue) for forming ValuesString . I understand now. tejaswi_teja wrote: just now have seen while trying to print into number fields it is giving normally but while printing text values , the value of the cell is shown as normally only but preceded by a ' symbol when double clicking on the cell. after dblclk on cell the value is like '1234 for text, copy cell contents and paste it elsewhere in note pad they appearing like: ECMName MID_Hex peninsula 5678 Since the single quote marks in each cell are for display purposes only (they tell Excel to treat the text exactly as you have entered it), and does not affect printing or pasting to other applications, is there any harm in leaving them there?


                "One must learn from the bite of the fire to leave it alone." - Native American Proverb

                T Offline
                T Offline
                tejaswi teja
                wrote on last edited by
                #7

                nothing harm just. just i was afraid if sbdy access the contents of that file along its original contents these quotes may also come and disturb. thats why. no other problems.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups