Jump to content

Exportar para Excel


obamaself
 Share

Recommended Posts

Boas estou a exportal uma datagridview para Excel.

O único problema é que numa das colunas tenho datas e ao exportar por exemplo o mês de março, ficam assim no excel:

20-03-2012

13-03-2012

03-02-2012

03-02-2012

03-01-2012

03-01-2012

03-01-2012

03-01-2012

03-01-2012

03-01-2012

Alguns com o dia trocado.

Link to comment
Share on other sites

20-03-2012

13-03-2012

03-02-2012

03-02-2012

03-01-2012

03-01-2012

03-01-2012

03-01-2012

03-01-2012

03-01-2012

13-03-2012

objExcelSheet.Cells.Columns(12).NumberFormat = "dd/mm/yyyy"

e também

objExcelSheet.Cells.Columns(12).NumberFormat = "dd/MM/yyyy"

Link to comment
Share on other sites

não da :s

Inserir na datagridview

Dim novalinha As DataRow = dt.NewRow
novalinha("data") = d.Data

Formato da coluna:

 DG.Columns("data").DefaultCellStyle.Format = "d"

Exportar para excel:

 objExcelSheet.Cells(dgvRowIndex, dgvCellIndex) = cell.Value

Além de me exportar também as horas, exporta me mal.

20-03-2012 01:25:51

13-03-2012 22:20:51

03-02-2012 14:44

03-02-2012 14:44

Link to comment
Share on other sites

Em vez de percorrer a Grid, percorre o DataSet, ou então ao passares para lá os valores, na coluna onde tem a data força a conversão para data, tipo

objExcelSheet.Cells(dgvRowIndex, dgvCellIndex) = Convert.ToDateTime(cell.Value)

Pedro Martins

Não respondo a duvidas por PM

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.