Bugün uzun bir süre için bana hizmet ve henüz hala kullanmak olan bir örnek göstermek istiyorum.
Biz ne olursa olsun, sütun veya sahip satır sayısı Excel tam bir DataTable vermek için bir örnek vereyim.
Orada bunu yapmak için pek çok yöntem olabilir, ancak bu yöntem Excel herhangi bir sürümü için çalışıyor çünkü ben gerçekten faydalı bulabilirsiniz. Excel'in daha yeni sürümleri ile compatilidad sorunlar için yalnızca 256 sütun anlaştım.
Biz gereken ilk şey Microsoft.Office.Interop.Excel için bir başvuru eklemek için ve biz aşağıdaki gibi yapın:

Excel için referans alma

İthalat Excel başvuru
Sonra bir form, bir düğme, dataGridView ve ilerleme çubuğu gerekir. Biz resimde görüldüğü olabilir:

Excel veri kümesi ihracat Başvuru formu
Şimdi tüm kod en önemli şey, herhangi bir tabloya adapte olması gerçekten basit olduğunu göstermek istiyoruz. Siz sorun olmadan yeniden mümkün olacak.
Imports System.Data System.Data.SqlClient Public Class New DataSet Private Sub Form1_Load (System.EventArgs olarak System.Object, ByVal e ByVal sender As) gibi Form1 İthalat Microsoft.Office.Interop Private ds içe MyBase.Load '/ / / Kolları / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / '/ / bağlantı oluştur ve DataGridView '/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / fill As New SqlConnection / / / / / / / / Dim cnn ("Data Source = localhost \ sqlexpress; Initial Catalog = Northwind; Integrated Security = True") Yeni SqlDataAdapter ("müşteri Select * from", cnn) Dim da verir. Fill (ds) = ds.Tables (0) DataGridView1.DataSource End Sub btnExportar_Click (System.EventArgs olarak System.Object, ByVal e ByVal sender As) Kolları / / / / / / / / / / / btnExportar.Click ' / / / / / / / / / / / / / / / / / / '/ / Excel nesne oluştur' / / / / / / / / / / / / / / / / / / / / / / / / / / / / / Dim Dim m_Excel objLibroExcel Dim objHojaExcel m_Excel = CreateObject ("Excel.Application") m_Excel.Workbooks.Add objLibroExcel = () = objLibroExcel.Worksheets objHojaExcel (1) objHojaExcel.Name = "Müşteriler" objHojaExcel.Visible = Excel . XlSheetVisibility.xlSheetVisible (objHojaExcel.Activate) '/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / '/ / satır ve sütun kontrol etmek için iki değişken tanımlamak' / / / / / / / / / / / / / / / / / / / / / Integer = 1 Dim sütun As / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / Dim satır As Integer = 1 '/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / '/ / Biz / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / sütun başlıkları 'ile satırı aşağıdaki şekilde / / / / / / / / / objHojaExcel.Range ("A1"). ds.Tables In Her dc (0) için) (seçin. Sütunlar objHojaExcel.Range (ColumnName (sütun) ve 1). Değer = dc.ColumnName kolon + = 1 Sonraki satır + = 1 '/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / '/ / Biz satır başlıkları biçimlendirmek' / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / objRango.Font: Excel.Range = objHojaExcel.Range objRango (. & ColumnName (ds.Tables (0) Columns.Count) ve "1" "A1") gibi / / / / / / / / / / / / / Dim . Kalın = True objRango.Cells.Interior.ColorIndex = 35 objRango.Cells.Borders (Excel.XlBordersIndex.xlDiagonalDown). LineStyle = Excel.XlLineStyle.xlLineStyleNone objRango.Cells.Borders (Excel.XlBordersIndex.xlDiagonalUp). LineStyle = Excel. XlLineStyle.xlLineStyleNone objRango.Cells.Borders (Excel.XlBordersIndex.xlEdgeLeft). LineStyle = Excel.XlLineStyle.xlLineStyleNone objRango.Cells.Borders (Excel.XlBordersIndex.xlEdgeRight). LineStyle = Excel.XlLineStyle.xlContinuous objRango.Cells.Borders (Excel . XlBordersIndex.xlEdgeTop). LineStyle = Excel.XlLineStyle.xlContinuous objRango.Cells.Borders (Excel.XlBordersIndex.xlEdgeBottom). LineStyle Excel.XlLineStyle.xlContinuous = '/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / '/ / datatable tüm satırları yerleştirin' / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / ProgressBar1.Maximum = ds.Tables (0). Rows.Count ProgressBar1.Value sütun = 1 = 0 Her ds.Tables (0) olarak dr. Satır sütun ds.Tables In Her dc (0) için = 1. Sütunlar objHojaExcel.Range (ColumnName (sütun) ve satır). Değer = dr (dc.ColumnName) sütun + = 1 Sonraki satır + 1 = + = 1 Sonraki ProgressBar1.Value '/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / '/ / otomatik olarak genişliğini ayarlamak' / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / kullanılan tüm sütunlar için / / / / / / / / objRango = objHojaExcel.Range ("A1:".. & ColumnName (ds.Tables (0) Columns.Count) & ds.Tables (0) Rows.Count.ToString) objRango.Select () objRango . Columns.AutoFit () '/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /' / / Biz söyle Excel gösterilecek '/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / MsgBox ("Komple Excel Export" için , MsgBoxStyle.Information, ". :: solovb.net ::.") m_Excel.Visible = True End Dize sütun As String Dim kolon (256) gibi Sub Public Function ColumnName (Integer ByVal sayısı) (1) = "A" sütunu (2) = "B" sütunu (3) = "C" kolonu (4) = "D" sütunu (5) = "E" kolonu (6) = "F" kolonu (7) = "G" kolonu ( 8) = "H" kolonu (9) = "I" kolonu (10) = "J" kolonu (11) = "K" kolonu (12) "L" = kolonu (13) = "M" kolonu (14) = "N" sütunu (15) = "W" sütununda (16) = "P" sütununda (17) = "Q" sütununda (18) = "R" sütununda (19) = "S" sütununda (20) = " T "kolonu (21) =" U "kolonu (22) =" V "kolonu (23) =" W "kolonu (24) =" X "kolonu (25) =" Y "kolonu (26) =" Z " Sütun (27) = "AA" sütununda (28) = "AB" sütunu (29) = "AC" sütununda (30) = "AD" sütununda (31) = "AE" sütununda (32) = "AF" sütununda ( 33) = "AG" Sütun (34) = "AH" sütununda (35) = "Sayı" sütununda (36) = "AJ" sütununda (37) = "AK" sütununda (38) = kolon (39) "İÇİN" = "AM" sütununda (40) = "NA" sütununda (41) = "AO" sütununda (42) = "AP" sütununda (43) = "AQ" sütununda (44) = "RA" sütununda (45) = " "" sütununda (46) = "AT" sütununda (47) = "AU" sütununda (48) = "AV" sütununda (49) = "AW" sütununda (50) = "AX" sütununda (51) = "AY GİBİ kolon (52) = "AZ" sütununda (53) = "BA" sütununda (54) = "BB" sütununda (55) = "BC" sütununda (56) = "BD" sütununda (57) = "BE" sütununda ( 58) = "BF" sütununda (59) = "BG" sütununda (60) = "BH" sütununda (61) = "BI" sütununda (62) = "BJ" sütununda (63) = "BK" sütununda (64) = "BL" sütununda (65) = "BM" sütununda (66) = "BN" sütununda (67) = "BO" sütununda (68) = "BP" sütununda (69) = "BA" sütununda (70) = " BR "sütununda (71) =" BS "sütununda (72) =" BT "sütununda (73) =" BU "sütununda (74) =" BV "sütununda (75) =" BW "sütununda (76) =" BX " kolon (77) = "BY" sütununda (78) = "BZ" sütununda (79) = "CA" sütununda (80) = "CB" sütununda (81) = "CC" sütununda (82) = "CD" sütununda ( 83) = "CE" sütununda (84) = "CF" sütununda (85) = "CG" sütununda (86) = "CH" sütununda (87) = "CI" sütununda (88) = "CJ" sütununda (89) = "CK" sütununda (90) = "CL" sütununda (91) = "CM" sütununda (92) = "CN" sütununda (93) = "CO" sütununda (94) = "CP" sütununda (95) = " CQ "sütununda (96) =" CR "sütununda (97) =" CS "sütununda (98) =" CT "sütununda (99) =" CU "sütununda (100) =" CV "sütununda (101) =" CW " kolon (102) = "CX" sütununda (103) = "CY" sütununda (104) = "CZ" sütununda (105) = "DA" sütununda (106) = "DB" sütununda (107) = "DC" sütununda ( 108) = "DD" sütununda (109) = "DE" sütununda (110) = "DF" sütununda (111) = "DG" sütununda (112) = "DH" sütununda (113) = "ID" sütununda (114) = "DJ" sütununa (115) = "DK" sütununda (116) = "DL" sütununda (117) = "DM" sütununda (118) = "DN" sütununda (119) = "DO" sütununda (120) = " DP "sütununda (121) =" DQ "sütununda (122) =" DR "sütununda (123) =" DS "sütununda (124) =" DT "sütununda (125) =" DU "sütununda (126) =" DV " kolon (127) = "DW" sütununda (128) = "DX" sütununda (129) = "DY" sütununda (130) = "DZ" sütununda (131) = "EA" sütununda (132) = "EB" sütununda ( 133) = "AK" sütununda (134) = "ED" sütununda (135) = "EE" sütununda (136) = "EF" sütununda (137) = "EG" sütununda (138) = "EH" sütununda (139) = "EI" sütununda (140) = "EJ" sütununda (141) = "EK" sütununda (142) = "EL" sütununda (143) = "MS" sütununda (144) = "IN" sütununda (145) = " EO "sütununda (146) =" EP "sütununda (147) =" EQ "sütununda (148) =" ER "sütununda (149) =" ES "sütununda (150) =" ET "sütununda (151) =" AB " kolon (152) = "EV" sütununda (153) = "EW" sütununda (154) = "EX" sütununda (155) = "EY" sütununda (156) = "EZ" sütununda (157) = "FA" sütununda ( 158) = "FB" sütununda (159) = "YP" sütununda (160) = "FD" sütununda (161) = "FE" sütununda (162) = "FF" sütununda (163) = "FG" sütununda (164) = "FH" sütununda (165) = "FI" sütununda (166) = "FJ" sütununda (167) = "FK" sütununda (168) = "FL" sütununda (169) = "FM" sütununda (170) = " FN "sütununda (171) =" FO "sütununda (172) =" FP "sütununda (173) =" CF "sütununda (174) =" FR "sütununda (175) =" FS "sütununda (176) =" FT " kolon (177) = "FU" sütununda (178) = "FV" sütununda (179) = "FW" sütununda (180) = "FX" sütununda (181) = "FY" sütununda (182) = "FZ" sütununda ( 183) = "GA" sütununda (184) = "GB" sütununda (185) = "GC" sütununda (186) = "GD" sütununda (187) = "GE" sütununda (188) = "GF" sütununda (189) = "GG" sütununda (190) = "GH" sütununda (191) = "GI" sütununda (192) = "GJ" sütununda (193) = "GK" sütununda (194) = "GL" sütununda (195) = " GM "sütununda (196) =" GN "sütununda (197) =" GO "sütununda (198) =" GP "sütununda (199) =" GQ "sütununda (200) =" GR "sütununda (201) =" GS " kolon (202) = "GT" sütununda (203) = "GU" sütununda (204) = "GV" sütununda (205) = "GW" sütununda (206) = "GX" sütununda (207) = "GY" sütununda ( 208) = "GZ" sütununda (209) = "HA" sütununda (210) = "HB" sütununda (211) = "HC" sütununda (212) = "HD" sütununda (213) = "HE" sütununda (214) = "HF" sütununda (215) = "HG" sütununda (216) = "SS" sütununda (217) = "HI" sütununda (218) = "HJ" sütununda (219) = "HK" sütununda (220) = " HL "sütununda (221) =" HM "sütununda (222) =" HN "sütununda (223) =" HO "sütununda (224) =" HP "sütununda (225) =" HQ "sütununda (226) =" HR " kolon (227) = "HS" sütununda (228) = "HT" sütununda (229) = "HU" sütununda (230) = "YG" sütununda (231) = "HW" sütununda (232) = "H" sütununa ( 233) = "HY" sütununda (234) = "HZ" sütununda (235) = "IA" sütununda (236) = "IB" sütununda (237) = "IC" sütununda (238) = "ID" sütununda (239) = "IE" sütununda (240) = "EĞER" sütununda (241) = "IG" sütununda (242) = "IH" sütununda (243) = "II" sütununda (244) = "IJ" sütununda (245) = " IK "sütununda (246) =" IL "sütununda (247) =" IM "sütununda (248) =" IN "sütununda (249) =" IO "sütununda (250) =" IP "sütununda (251) =" IQ " kolon (252) = "R" sütununda (253) = kolon (254) = "IT" sütununda (255) = "UI" sütununda (256) = "IV" Dönüş sütun (sayı) End Function End Class "IS" Bu yöntem bana hizmet vermiştir ve ben de bunu umuyoruz ... yorumlarınızı bırakın lütfen.
Bilgi Bitacoras.com ...
Bitacoras.com Puan Ver: Merhaba, Bugün ben uzun bir süre için bana hizmet ve henüz hala kullanmak olan bir örnek göstermek istiyorum. Biz Teng bu sütun sayısı veya satır bakılmaksızın Excel tam bir DataTable vermek için bir örnek yapacak .....
İyi ...
Mükemmel mesaj! Bana tam yardım ederiz, ama bir şüphe var .. Sql bağlantısı ile olduğu gibi .. Nasıl sütunlar yeniden adlandırmak yok!? Bu sql alanlarında adını getiriyor çünkü ..!
Umarım ve anladım ..
Teşekkür ederiz!
Ben kazanmak için gidiyorum ...
bir noktada faydalı olacaktır ...
Bu Excel 2007 için geçerli mi? Ben 2007 için daha önceki sürümleri için geçerlidir, ama o, geliştirmek için ihracat ile ilgili sorunlar vardı. Teşekkürler
Muazzam kaynak kodu. bana hizmet. q uzun gecikmiş oldu.
Aynı zamanda bir veri tablosunun ithalat ecxel gerekir rağmen. ancak bir veri çevresel olabilir ve daha sonra DataAdapter güncellenmesi ve datatable değişiklikleri kabul q bd kaydedilmiş olacaktır ... Ben yardımcı olabilir ya da bulmayı umuyorum .. teşekkürler
Merhaba çok teşekkür ederiz! Bu mükemmel!
Datagrid birkaç Datagrid olduğu durumda kullanılan belirtir Ama nerede acaba?
Masanın üzerinde bir çağrı konum ...
select * from (tablo adı)
Hangi alanları istediğiniz belirtmek istiyorsanız
* tablodan (alanları, alanları, alanları) seçin
ejm
araba araba, renk, yıl seçin
Ben değişkenleri dc ve dr 2 hata yaparlar bu örnek ile ilgili bir sorun var, bunu düzeltmek için ne yapabilirim?
Merhaba, bu deneyin:
Ds.Tables yılında DataRow (0) olarak her dr için. Satırlar ve DataColumn ds.Tables In Her dc olarak (0) için. Sütunlar
Bu çözülürse umuyoruz. Selamlar.
hola.
Bu chevere, ancak sütun adının bir parçası çok işlevsel değildir.
Blogumun çok daha küçük bir kod boyutu sınırlamaları ve olmayan karşıya olacak
jaysson.blogspot.com
hazır ve makale gitti
http://jaysson.blogspot.com/2010/06/columnas-es-excel.html
İyi makale, ama sorunsuz Excel 2007 çalışmaları ile benim bilgisayarda bir sorun var, ama Excel ile bilgisayarlar ile 2003 veya önceki çalışmıyor. Kütüphanelerin sorunu ithal olduğunu eğer herhangi bir excel çalışmaları ima beri herkes, biliyorum, ama bu sorunla karşılaştı.
Birisi şüphe çözebilir Bakalım.
Teşekkür ederim.
İyi ...
Mükemmel mesaj! Bana tam yardım ederiz, ama bir şüphe var .. Sql bağlantısı ile olduğu gibi .. Nasıl sütunlar yeniden adlandırmak yok!? Bu sql alanlarında adını getiriyor çünkü ..!
Umarım ve anladım ..
Teşekkür ederiz!
Public Sub ExportarDatosExcel (As String DataGridView, ByVal başlık ByVal DataGridView1)
Yeni Excel.Application Dim m_Excel gibi
m_Excel.Cursor = Excel.XlMousePointer.xlWait
m_Excel.Visible = True
Excel.Workbook Dim objLibroExcel = m_Excel.Workbooks.Add gibi
Excel.Worksheet Dim objHojaExcel = objLibroExcel.Worksheets (1)
ObjHojaExcel ile
. Visible = Excel.XlSheetVisibility.xlSheetVisible
. Activate ()
'Başlık
. Range ("A1: L1").) (Birleştirme
. Range ("A1: L1"). Value = "ENSTİTÜSÜ ARGENCAF"
. Range ("A1: L1"). Font.Bold = True
. Range ("A1: L1"). = 15 Font.Size
'Püskül
. Range ("A2: L2").) (Birleştirme
. Range ("A2: L2"). Değer = title
. Range ("A2: L2"). Font.Bold = True
. Range ("A2: L2"). = 12 Font.Size
Char olarak Const primeraLetra = "A"
Kısa = 3 gibi Const firstNumber
UltimaLetra gibi Char, Char Dim mektup
As Integer Dim sayısı, As Integer UltimoNumero
1 - Byte = Asc cod_letra (primeraLetra) Dim
String = Application.CurrentCulture.NumberFormat.NumberDecimalSeparator sepDec Dim
String = Application.CurrentCulture.NumberFormat.NumberGroupSeparator sepMil Dim
Hesaplama kızı sütun 'Set formatı
"" String = As StrColumna Dim
"" String = As LetraIzq Dim
1 - Byte = Asc cod_LetraIzq (primeraLetra) Dim
Mektubu = primeraLetra
Number = firstNumber
Excel.Range Dim objCelda gibi
DataGridView1.Columns yılında olduğu gibi DataGridViewColumn Her c için
Sonra c.Visible eğer
Mektubu = "Z", eğer
Mektubu = primeraLetra
cod_letra = Asc (primeraLetra)
cod_LetraIzq + = 1
LetraIzq = Chr (cod_LetraIzq)
Başka
cod_letra + = 1
Mektubu = Chr (cod_letra)
End If
strColumna = LetraIzq + Lyrics + Numero.ToString
objCelda =. Range (strColumna, Type.Missing)
objCelda.Value = c.HeaderText
= 8 objCelda.EntireColumn.Font.Size
'ObjCelda.EntireColumn.NumberFormat = c.DefaultCellStyle.Format
C.ValueType midir Eğer GetType (Decimal) OrElse c.ValueType Sonra GetType (Çift) mı
objCelda.EntireColumn.NumberFormat = "#" + sepMil + "0" + sepDec + "00"
End If
End If
Sonraki
Excel.Range Dim objRangoEncab =. Range (primeraLetra + Numero.ToString, LetraIzq + Lyrics + Numero.ToString) gibi
objRangoEncab.BorderAround (1, Excel.XlBorderWeight.xlMedium)
UltimaLetra = Gönder
String = LetraIzq UltimaLetraIzq Dim
'LOAD DATA
Dim i As Integer = Sayı + 1
DataGridViewRow DataGridView1.Rows gibi her ayında Listesi
LetraIzq = ""
cod_LetraIzq = Asc (primeraLetra) - 1
Mektubu = primeraLetra
cod_letra = Asc (primeraLetra) - 1
DataGridView1.Columns yılında olduğu gibi DataGridViewColumn Her c için
Sonra c.Visible eğer
Mektubu = "Z", eğer
Mektubu = primeraLetra
cod_letra = Asc (primeraLetra)
cod_LetraIzq + = 1
LetraIzq = Chr (cod_LetraIzq)
Başka
cod_letra + = 1
Mektubu = Chr (cod_letra)
End If
strColumna = LetraIzq + Lyrics
"Burada yük olmalıdır
. Cells (i, strColumna) = IIf (IsDBNull (reg.ToString) "," reg.Cells (c.Index). Değer)
'. Cells (i, strColumna) = IIf (IsDBNull (atılmaz (c.DataPropertyName)), c.DefaultCellStyle.NullValue, reg (c.DataPropertyName))
'. Aralığı (strColumna + i, strColumna + i). In ()
End If
Sonraki
Excel.Range Dim objRangoReg gibi. = Range (primeraLetra + i.ToString, i.ToString strColumna +)
objRangoReg.Rows.BorderAround ()
objRangoReg.Select ()
i + = 1
Sonraki
UltimoNumero = i
Sütunların "Beraberlik hatları
LetraIzq = ""
cod_LetraIzq = Asc ("A")
cod_letra = Asc (primeraLetra)
Mektubu = primeraLetra
DataGridView1.Columns yılında olduğu gibi DataGridViewColumn Her c için
Sonra c.Visible eğer
. objCelda = Range (LetraIzq + Lyrics + primerNumero.ToString, LetraIzq + Lyrics + (UltimoNumero -. 1) ToString)
objCelda.BorderAround ()
Mektubu = "Z", eğer
Mektubu = primeraLetra
cod_letra = Asc (primeraLetra)
LetraIzq = Chr (cod_LetraIzq)
cod_LetraIzq + = 1
Başka
cod_letra + = 1
Mektubu = Chr (cod_letra)
End If
End If
Sonraki
'Kalın dış sınır çizin
. (. - 1) ToString primeraLetra + primerNumero.ToString, UltimaLetra UltimaLetraIzq + + (UltimoNumero) Excel.Range dim objRango = aralığı itibarıyla
objRango.Select ()
() objRango.Columns.AutoFit
objRango.Columns.BorderAround (1, Excel.XlBorderWeight.xlMedium)
End With
m_Excel.Cursor = Excel.XlMousePointer.xlDefault
End Sub
ToolStripButton2_Click_1 Private Sub (System.EventArgs As System.Object, ByVal e ByVal sender As) ToolStripButton2.Click Kolları
ExportarDatosExcel (DataGridView1, "ihracat")
End Sub
MÜKEMMEL! .... teşekkürler kardeşim, ve ithalat / ihracat Excel ve hiçbir şey için bir modül ile 3 gün süren çalıştı .... ama çözümü ile ben arequipa yine yıldızlar ... selam bakın:! ..
Bir şey değil. Ben size bir örnek olarak hizmet memnunum.
Bu kod, bu yüzden benim iki kuruş ile işbirliği, bana çok yardım etti:
Ahsta ZZ sütun gelmesi "ColumnName" optimize (702 vd.)
İşte sana bir kod verir:
As String Public Function ColumnName (Integer ByVal numarası)
As String Dim kolon (703)
Sütun (1) = "A"
sütunu (2) = "B"
sütunu (3) = "C"
sütunu (4) = "D"
sütunu (5) = "E"
sütunu (6) = "F"
sütunu (7) = "G"
sütunu (8) = "H"
sütunu (9) = "I"
kolon (10) = "J"
kolon (11) = "K"
kolon (12) "L" =
kolon (13) = "M"
kolon (14) = "N"
kolon (15) = "O"
Sütun (16) = "P"
kolon (17) = "S"
kolon (18) = "R"
kolon (19) = "S"
kolon (20) = "T"
kolon (21) = "U"
kolon (22) = "V"
kolon (23) = "W"
kolon (24) = "X"
kolon (25) = "Y"
kolon (26) = "Z"
Dim i = 27
Ltr1 için = 1 To 26
Ltr2 için = 1 To 26
sütun: (i) = kolonu (Ltr1) ve sütunun (Ltr2)
i + = 1
Sonraki
Sonraki
İade sütun (sayı)
End Function
TECKNOCK,! Yardımlarınız için çok teşekkür ederim, ama yarattığımız kitabın izin Excel 97-2003 maksimum sütunlar ile uyumlu olup olmadığını 256 (IV) olduğunu unutmayın. Yorum hesaba almak gibi.
Elisha
Ben doğru yerel uygulama funcioana koşuyorum, ama ben bir web sitesinde yüklediğinizde excel yaratmaz ama hata alamadım zaman
Benim sql A TOPRAKLI haciend arıyorum
ben yapıyordum ama AJA Yapmayacağız gibi
Ben burada olan her şekilde yapmaya çalışacağım yardıma ihtiyacım var ve ben hata alıyorum
El, size mükemmel funca maksimum konum.
[...] [...]
çok iyi, tebrikler iyi yazı okudum ve istişare ettik edilir
Teşekkür ederiz! Bu çok yararlı oldu
Hey kod bana çalışmayan bir da.Fill hataları işaretler (ds)
Ben hata işaretlemek SqlException bulunmadı
bana yardım edebilir
bir soru excel doğrudan yükleme sql sorgusu yapabilir?
önceden yoluyla
merhaba bütün agradesco katkınız ilk arkadaş.
Seni ben office 2010 yüklü ve benim sorunum olamaz, hangi gösterir referans bulamıyorum bir sorun olduğunu unutmayın.
size agradeseria bazı tavsiyeler.
Merhaba, çok iyi bir katkı Ben arıyordum ne olduğunu ... ama geliştirme sunucudan çalıştırdığınızda mükemmel çalışır, ama başka bir pc den web eriştiğinizde hiçbir şey ... hiçbir hata yapar ama kayıt olmayan birşeyi yok ...
Herkes bunu düzeltmek nasıl biliyor?
Çok teşekkür ederim, bana örnek oldu ama doğrudan bir tablo içinde depolanan değerleri bana bir Excel dosyası oluşturan bir fonksiyon oluşturmak için bir temel olarak ne dejor durumda birisi için yararlı olduğunu
'/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
'/ / Biz sütun başlıkları satırı aşağıdaki şekilde
'/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
objHojaExcel.Range ("A1").) (seçin
As Integer Dim I = 0
As Integer Dim Lncol = 1
DgvSocios.Columns In Her dc için
DgvSocios.Columns.Item (I). Visible = True Sonra ise
objHojaExcel.Range (ColumnName (lncol) & 1). Değer = dgvSocios.Columns.Item (I). HeaderText
lncol + = 1
End If
I + = 1
Sonraki
satır + 1 =
'/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
'/ / Biz satır başlıkları biçimlendirmek
'/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
Excel.Range Dim objRango = objHojaExcel.Range (: & ColumnName (lncol) ve "1" "A1") gibi
objRango.Font.Bold = True
objRango.Cells.Interior.ColorIndex = 35
objRango.Cells.Borders (Excel.XlBordersIndex.xlDiagonalDown). LineStyle = Excel.XlLineStyle.xlLineStyleNone
objRango.Cells.Borders (Excel.XlBordersIndex.xlDiagonalUp). LineStyle = Excel.XlLineStyle.xlLineStyleNone
objRango.Cells.Borders (Excel.XlBordersIndex.xlEdgeLeft). LineStyle = Excel.XlLineStyle.xlLineStyleNone
objRango.Cells.Borders (Excel.XlBordersIndex.xlEdgeRight). LineStyle = Excel.XlLineStyle.xlContinuous
objRango.Cells.Borders (Excel.XlBordersIndex.xlEdgeTop). LineStyle = Excel.XlLineStyle.xlContinuous
objRango.Cells.Borders (Excel.XlBordersIndex.xlEdgeBottom). LineStyle = Excel.XlLineStyle.xlContinuous
'/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
'/ / Datatable tüm satırları yükleyin
'/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
ProgressBar1.Maximum = dgvSocios.Rows.Count
kolon = 0
ProgressBar1.Value = 0
ProgressBar1.Visible = True
Integer = 0 olarak Lnfila Dim
I = 1
DgvSocios.Rows In Her dr için
kolon = 0
DgvSocios.Columns In Her dc için
DgvSocios.Columns.Item (sütun). Visible = True Sonra ise
objHojaExcel.Range (ColumnName (I) ve satır). Değer = dgvSocios.Item (sütun, lnfila). Value.ToString
I + = 1
End If
Sütun + = 1
Sonraki
lnfila + = 1
satır + 1 =
ProgressBar1.Value + = 1
Sonraki
'/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
'/ / Otomatik olarak genişliğini ayarlamak
Kullanılan tüm sütunları itibaren '/ /
'/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
objRango = objHojaExcel.Range ("A1:" & ColumnName (lncol) & (lnfila + 1) ToString.)
objRango.Select ()
() objRango.Columns.AutoFit
'/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
'/ / Biz Excel görüntülemek için söyle
'/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
MsgBox (MsgBoxStyle.Information "Excel Komple verme", ". :: Solovb.net ::.")
m_Excel.Visible = True
Bu fonksiyon için biraz getiren aşağıdaki kod işlevi "ColumnName" gerektirmez için "Aralık" kullanımını önler
Saygılarımızla,
Imports System.Data
Imports System.Data.SqlClient
İthalat Microsoft.Office.Interop.Excel
Kamu Modülü Mutil
Public Sub ExportarDtToExcel (As String System.Data.DataTable, ByVal başlık ByVal Dt)
Excel.Application Dim m_Excel gibi
Excel.Workbook Dim objLibroExcel gibi
Worksheet Dim objHojaExcel gibi
Denemek
'/ / / / / / / / / / / / / / / / / / / / / / / / / / / / /
'/ / Excel nesne oluşturma
'/ / / / / / / / / / / / / / / / / / / / / / / / / / / / /
m_Excel = CreateObject ("Excel.Application")
m_Excel.Workbooks.Add objLibroExcel = ()
objHojaExcel = objLibroExcel.Worksheets (1)
objHojaExcel.Name = Başlık
objHojaExcel.Visible = Excel.XlSheetVisibility.xlSheetVisible
() objHojaExcel.Activate
'/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
'/ / Satır ve sütun kontrol etmek için iki değişken tanımlayın
'/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
Integer = 1 Dim satır
Integer = 1 Dim sütun
'/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
'/ / Biz sütun başlıkları satırı aşağıdaki şekilde
'/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
'ObjHojaExcel.Range ("A1").) (Seçin
objHojaExcel.Cells (satır, sütun).) (SEÇ
Dt.Columns In Her dc için
objHojaExcel.Cells (satır, sütun). Değer = dc.ColumnName
Sütun + = 1
Sonraki
satır + 1 =
'/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
'/ / Biz satır başlıkları biçimlendirmek
'/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
Excel.Range = loş objRango objHojaExcel.Range (objHojaExcel.Cells (1, 1), objHojaExcel.Cells (1, Dt.Columns.Count)) gibi
objRango.Font.Bold = True
objRango.Cells.Interior.ColorIndex = 35
objRango.Cells.Borders (Excel.XlBordersIndex.xlDiagonalDown). LineStyle = Excel.XlLineStyle.xlLineStyleNone
objRango.Cells.Borders (Excel.XlBordersIndex.xlDiagonalUp). LineStyle = Excel.XlLineStyle.xlLineStyleNone
objRango.Cells.Borders (Excel.XlBordersIndex.xlEdgeLeft). LineStyle = Excel.XlLineStyle.xlLineStyleNone
objRango.Cells.Borders (Excel.XlBordersIndex.xlEdgeRight). LineStyle = Excel.XlLineStyle.xlContinuous
objRango.Cells.Borders (Excel.XlBordersIndex.xlEdgeTop). LineStyle = Excel.XlLineStyle.xlContinuous
objRango.Cells.Borders (Excel.XlBordersIndex.xlEdgeBottom). LineStyle = Excel.XlLineStyle.xlContinuous
'/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
'/ / Datatable tüm satırları yükleyin
'/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
kolon = 1
Dt.Rows In Her dr için
kolon = 1
Dt.Columns In Her dc için
objHojaExcel.Cells (satır, sütun). Değer = dr (dc.ColumnName)
Sütun + = 1
Sonraki
satır + 1 =
Sonraki
'/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
'/ / Otomatik olarak genişliğini ayarlamak
Kullanılan tüm sütunları itibaren '/ /
'/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
objHojaExcel.Cells objRango = (1, Dt.Columns.Count)
objRango.Select ()
() objRango.Columns.AutoFit
'/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
'/ / Biz Excel görüntülemek için söyle
'/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
MsgBox (MsgBoxStyle.Information "Excel Komple verme", "İhracat")
m_Excel.Visible = True
İstisna olarak Catch ex
MsgBox (ex.ToString)
Nihayet
objHojaExcel = Nothing
objLibroExcel = Nothing
m_Excel = Nothing
End Try
End Sub
End Module