Ruben_Barbosa Posted November 13, 2009 at 11:40 AM Report Share #295955 Posted November 13, 2009 at 11:40 AM Ola, O meu problema é o seguinte: A minha data é um DataTimerP1 que exporta a informação para excel com string e nao como Data. Agora o meu Problema é o Seguinte quando faco um exporta de informação de VB.NET para excel o que me acontece é Se a data for inferior a actual ele escreve-me MM/DD/AAAA no Excel Se a data for igual ou superior ele Escreve-me DD/MM/AAAA no Excel Tambem pensei por o meu office ser um 2007 em portugues e o VB.net em ingles mas dps de meter a informação como string devia comer tudo certo ?. É esse o meu problema é Se a data for inferior a actual ele escreve-me MM/DD/AAAA no Excel e quero que escreve DD/MM/AAAA Link to comment Share on other sites More sharing options...
ribeiro55 Posted November 13, 2009 at 12:35 PM Report Share #295964 Posted November 13, 2009 at 12:35 PM Como estás a escrever a data no Excel? Tens de mostrar os teus métodos de escrita e leitura para que se possa tirar conclusões. Sérgio Ribeiro "Great coders aren't born. They're compiled and released""Expert coders do not need a keyboard. They just throw magnets at the RAM chips" Link to comment Share on other sites More sharing options...
Ruben_Barbosa Posted November 13, 2009 at 12:45 PM Author Report Share #295966 Posted November 13, 2009 at 12:45 PM 'EXTRAIR INFORMACÃO PARA EXCEL Try Dim objApp As Object objApp = CreateObject("Excel.Application") Dim xlw As Microsoft.Office.Interop.Excel.Workbook Dim i As Integer = 0 Dim j As Integer = 0 Dim oldCI As System.Globalization.CultureInfo = _ System.Threading.Thread.CurrentThread.CurrentCulture System.Threading.Thread.CurrentThread.CurrentCulture = _ New System.Globalization.CultureInfo("en-US") xlw = objApp.Workbooks.Add xlw.Sheets(1).Select() objApp.ActiveSheet.Cells(1, 1) = "ID FOLHAS" objApp.ActiveSheet.Cells(1, 2) = "Departamento" objApp.ActiveSheet.Cells(1, 3) = "Utilizador" objApp.ActiveSheet.Cells(1, 4) = "Data Requisição" objApp.ActiveSheet.Cells(1, 5) = "Quantidade Unitária" objApp.ActiveSheet.Cells(1, 6) = "Observação" objApp.Columns.AutoFit() For i = 0 To DataGridView1.Rows.Count - 1 'Numero de Linhas para extrair informação objApp.Columns.AutoFit() For j = 0 To DataGridView1.Columns.Count - 1 'Numero de Colunas Com os Nomes para a BD xlw.Application.Cells(i + 2, j + 1).value = DataGridView1.Rows(i).Cells(j).Value Next Next 'Nex objApp.Visible = True Catch MsgBox("O EXCEL não pode ser iniciado!", vbCritical) End Try Link to comment Share on other sites More sharing options...
ribeiro55 Posted November 13, 2009 at 12:54 PM Report Share #295967 Posted November 13, 2009 at 12:54 PM System.Globalization.CultureInfo("en-US") DataGridView1.Rows(i).Cells(j).Value E aposto que o teu campo da base de dados é DateTime. Estás-lhe a dar uma "culture" diferente da que queres empregar e estás a usar o Value da célula. Ou seja, com a culture errada, ele vai apanhar a data nesse formato. Depois o value contém o respectivo data type e não string. Ou alteras o culture info e deve ficar OK, ou tens de adicionar lá em baixo no ciclo uma verificação para ver os nomes das colunas e se o nome da coluna for o campo de data, convertes o value para data e vais extraír os elementos com a ordem que pretendes. Sérgio Ribeiro "Great coders aren't born. They're compiled and released""Expert coders do not need a keyboard. They just throw magnets at the RAM chips" Link to comment Share on other sites More sharing options...
Ruben_Barbosa Posted November 13, 2009 at 01:00 PM Author Report Share #295970 Posted November 13, 2009 at 01:00 PM Não na minha Base de Dados o meu Campo Data é nvchar (ou seja aceita tudo). Link to comment Share on other sites More sharing options...
ribeiro55 Posted November 13, 2009 at 01:04 PM Report Share #295971 Posted November 13, 2009 at 01:04 PM Então troca DataGridView1.Rows(i).Cells(j).Value para DataGridView1.Rows(i).Cells(j).Value.ToString e usa Debug.Print(DataGridView1.Rows(i).Cells(j).Value.ToString) para veres o que realmente vem da base de dados, para entendermos onde é que a conversão se está a dar. Sérgio Ribeiro "Great coders aren't born. They're compiled and released""Expert coders do not need a keyboard. They just throw magnets at the RAM chips" Link to comment Share on other sites More sharing options...
Ruben_Barbosa Posted November 13, 2009 at 03:31 PM Author Report Share #295993 Posted November 13, 2009 at 03:31 PM Obrigadissimo 😄 Ribeiro. Vou verificar. Link to comment Share on other sites More sharing options...
Ruben_Barbosa Posted November 16, 2009 at 12:18 PM Author Report Share #296460 Posted November 16, 2009 at 12:18 PM Ribeiro dá-me o seguinte Erro :|. Não sei pk é que ele nao me aceita a string :| http://img130.imageshack.us/img130/209/semttulom.jpg Link to comment Share on other sites More sharing options...
Ruben_Barbosa Posted November 16, 2009 at 12:29 PM Author Report Share #296463 Posted November 16, 2009 at 12:29 PM 'EXTRAIR INFORMACÃO PARA EXCEL Try Dim objApp As Object objApp = CreateObject("Excel.Application") Dim objBook As Microsoft.Office.Interop.Excel.Workbook Dim i As Integer = 0 Dim j As Integer = 0 Dim oldCI As System.Globalization.CultureInfo = _ System.Threading.Thread.CurrentThread.CurrentCulture System.Threading.Thread.CurrentThread.CurrentCulture = _ New System.Globalization.CultureInfo("en-US") objBook = objApp.Workbooks.Add objBook.Sheets(1).Select() objApp.ActiveSheet.Cells(1, 1) = "ID FOLHAS" objApp.ActiveSheet.Cells(1, 2) = "Departamento" objApp.ActiveSheet.Cells(1, 3) = "Utilizador" objApp.ActiveSheet.Cells(1, 4) = "Data Requisição" objApp.ActiveSheet.Cells(1, 5) = "Quantidade Unitária" objApp.ActiveSheet.Cells(1, 6) = "Observação" objApp.Columns.AutoFit() For i = 0 To DataGridView1.Rows.Count - 1 'Numero de Linhas para extrair informação objApp.Columns.AutoFit() For j = 0 To DataGridView1.Columns.Count - 1 'Numero de Colunas Com os Nomes para a BD TextBox1.Text = DataGridView1.Rows(i).Cells(j).Value objBook.Application.Cells(i + 2, j + 1).value = TextBox1.Text Next Next 'Nex objApp.Visible = True objApp = Nothing objBook = Nothing Catch MsgBox("O EXCEL não pode ser iniciado!", vbCritical) End Try resolvi assim 😛 e ocultei a textbox 🙂 e deu 😄 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now