{"id":24469,"date":"2017-01-12T15:22:28","date_gmt":"2017-01-12T14:22:28","guid":{"rendered":"http:\/\/help.qualiware.it\/qw-help\/?p=24469"},"modified":"2017-01-12T15:26:18","modified_gmt":"2017-01-12T14:26:18","slug":"importazione-di-un-file-excel","status":"publish","type":"post","link":"https:\/\/help.qualiware.it\/qw-help\/importazione-di-un-file-excel\/","title":{"rendered":"Importazione di un file Excel"},"content":{"rendered":"<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">' Il seguente frammento di codice importa un file Excel contenente 3 colonne: Anno, Mese e Data Chiusura\r\n' Pu\u00f2 essere facilmente riadattato per ogni esigenza\r\n' Nell'esempio vengono letti solo interi e date. Tenere presente che per leggere stringe, numeri in virgola mobile e booleani sono disponibili i metodi \"ReadString\", \"ReadFloat\" e \"ReadBoolean\" per l'oggetto \"x\"\r\nDim x As qwexcel\r\nDim i As Integer\r\nDim anno As Integer, mese As Integer\r\nDim dt As Date\r\nDim msg as string\r\nDim nfserver as string\r\n\r\n'nfserver=&lt;percorso del file da importare&gt;\r\nx = New qwexcel()\r\nx.Open(nfserver)\r\nx.SetActiveWorksheet(x.GetWorkbook.Worksheets(0).Name)\r\n\r\nIf Empty(x.ReadString(1,1)) Then\r\n msg = \"Il contenuto della Cella A1 \u00e8 risultato essere vuoto !\" + vbnewline + \"Il file Excel deve contenere una sequenza continua.\"\r\nElse\r\n For i = 2 To 100000\r\n     If Utils.isNumeric(x.ReadInteger(i,1)) Then\r\n        anno = x.ReadInteger(i,1)\r\n        mese = x.ReadInteger(i,2)\r\n \r\n        If Empty(anno) Or Empty(mese) Then\r\n           msg = \"ANNO e MESE non sono stati riconosciuti correttamente !\" + vbnewline + \"Riga n\u00b0 \" + cstr(i)\r\n           Exit For\r\n        End If\r\n \r\n        Dim par As AssocArray = New AssocArray\r\n        Dim q1 As qwtable\r\n \r\n        q1 = OpenTable(form, \"SELECT * FROM P_DATA_CHIUS_MESI\", par, False, True, msg)\r\n \r\n        If Empty(msg) Then\r\n           ' Task da compiere con il recordset\r\n           If Not q1.Rowset.Findkey(anno, mese) Then\r\n              q1.beginappend()\r\n              q1.Replace(\"ANNO\", anno)\r\n              q1.Replace(\"MESE\", mese)\r\n           End If\r\n  \r\n           If Not isDate(x.ReadDate(i,3)) Then\r\n              dt = Null\r\n           Else\r\n              dt = x.ReadDate(i,3)\r\n           End If\r\n \r\n           q1.Replace(\"DATA_CHIUS\", dt)\r\n           q1.Saverecord()\r\n        Else\r\n           ' Errore\r\n           Exit For\r\n        End If\r\n \r\n        CloseTable(form, q1)\r\n     End If\r\n Next\r\nEnd If\r\n\r\nx.Close()<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#8216; Il seguente frammento di codice importa un file Excel contenente 3 colonne: Anno, Mese e Data Chiusura &#8216; Pu\u00f2 essere facilmente riadattato per ogni esigenza &#8216; Nell&#8217;esempio vengono letti solo interi e date. Tenere presente che per leggere stringe, numeri in virgola mobile e booleani sono disponibili i metodi &#8220;ReadString&#8221;, &#8220;ReadFloat&#8221; e &#8220;ReadBoolean&#8221; per&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"ngg_post_thumbnail":0,"footnotes":""},"categories":[65],"tags":[71],"acf":[],"_links":{"self":[{"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/posts\/24469"}],"collection":[{"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/comments?post=24469"}],"version-history":[{"count":0,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/posts\/24469\/revisions"}],"wp:attachment":[{"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/media?parent=24469"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/categories?post=24469"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/tags?post=24469"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}