csharp export do excela z grida#c #devexpress #spreadsheet #devexpress #xaf
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp export do excela z grida#c #devexpress #spreadsheet #devexpress #xaf相关的知识,希望对你有一定的参考价值。
using ( Workbook workbook = new Workbook()) {
// Set the built-in document properties.
workbook.DocumentProperties.Title = "Zlecenie odczytu";
workbook.DocumentProperties.Description = String.Format( "Zlecenie odczytu radiowego DIEHL Metering numer {0}", ConfigPV6B.YTMZadanie.YTMZ_Numer?.Trim());
workbook.DocumentProperties.Keywords = "TM, GIGA, DIEHL Metering";
workbook.DocumentProperties.Company = "GIGA-Katowice";
Worksheet worksheet = workbook.Worksheets[0]; // .ActiveWorksheet;
//-- nagłówki
worksheet.Cells["A1"].Value = @"ID";
worksheet.Cells["B1"].Value = @"Billing contact - Contact#";
worksheet.Cells["C1"].Value = @"Device location - City";
worksheet.Cells["D1"].Value = @"Device location - Street";
worksheet.Cells["E1"].Value = @"Device location - Street number";
worksheet.Cells["F1"].Value = @"On-site contact - Mobile";
worksheet.Cells["G1"].Value = @"Consumer contact - Firstname";
worksheet.Cells["H1"].Value = @"Consumer contact - Lastname";
worksheet.Cells["I1"].Value = @"Position";
worksheet.Cells["J1"].Value = @"Device location - Latitude";
worksheet.Cells["K1"].Value = @"Device location - Longitude";
worksheet.Cells["L1"].Value = @"Device location - Floor";
worksheet.Cells["M1"].Value = @"Device location - Room";
worksheet.Cells["N1"].Value = @"Device location - Postcode";
worksheet.Cells["O1"].Value = @"Device location - Country";
//-- specyfikacja
var qPV6B = from p in new XPQuery<YTM_Zadanie_PV6B>( XpoDefault.Session )
where p.YTMZPV6B_IdZadanie == ConfigPV6B.YTMZadanie
select p;
int lp = 1;
foreach( YTM_Zadanie_PV6B pv6b in qPV6B ) {
//-- doczytaj brakujące obiekty
YWodomierz_Nadajnik xNadajnik = XpoDefault.Session.GetObjectByKey<YWodomierz_Nadajnik>( pv6b.YTMZPV6B_IdWodomierz_Nadajnik );
if ( xNadajnik == null ) {
continue;
}
YRozliczenie_Obiekt xFormula = XpoDefault.Session.GetObjectByKey<YRozliczenie_Obiekt>( pv6b.YTMZPV6B_IdRozliczenie_Obiekt );
if ( xFormula == null ) {
continue;
}
YAdres_Obiekt xAdresObiekt = XpoDefault.Session.GetObjectByKey<YAdres_Obiekt>( pv6b.YTMZPV6B_IdAdres_Obiekt );
if ( xAdresObiekt == null ) {
continue;
}
YWodomierz_Uzytkowany xMontaz = XpoDefault.Session.GetObjectByKey<YWodomierz_Uzytkowany>( pv6b.YTMZPV6B_IdWodomierz_Uzytkowany );
if ( xMontaz == null ) {
continue;
}
//-- buduje nr domu/nr lokalu
string adrNrDomu = xAdresObiekt.YAO_NrDomu?.Trim();
if (! string.IsNullOrWhiteSpace( xAdresObiekt.YAO_NrLokalu ))
adrNrDomu = adrNrDomu + @"/"+ xAdresObiekt.YAO_NrLokalu.Trim();
//-- szukam nr telefonu
string adrTelefon = string.Empty;
while (true) {
if (! string.IsNullOrWhiteSpace( xAdresObiekt.YAO_Telefon1)) {
adrTelefon = xAdresObiekt.YAO_Telefon1.Trim();
break;
}
if ( !string.IsNullOrWhiteSpace( xAdresObiekt.YAO_Telefon2 ) ) {
adrTelefon = xAdresObiekt.YAO_Telefon2.Trim();
break;
}
break;
}
//-- mamy wszystko, można zapisać do arkusza
lp++;
worksheet.Cells[string.Format( "A{0}", lp )].Value = string.Format( "{0}", xNadajnik.YWNA_Numer?.Trim() );
worksheet.Cells[string.Format( "B{0}", lp )].Value = string.Format( "{0,-20}{1,-20}", ConfigPV6B.YTMZadanie.YTMZ_Numer?.Trim(), xFormula.YROB_Akronim.Trim() );
worksheet.Cells[string.Format( "C{0}", lp )].Value = string.Format( "{0}", xAdresObiekt.YAO_Miasto?.Trim() );
worksheet.Cells[string.Format( "D{0}", lp )].Value = string.Format( "{0}", xAdresObiekt.YAO_Ulica?.Trim() );
worksheet.Cells[string.Format( "E{0}", lp )].Value = string.Format( "{0}", adrNrDomu );
worksheet.Cells[string.Format( "F{0}", lp )].Value = string.Format( "{0}", adrTelefon );
worksheet.Cells[string.Format( "G{0}", lp )].Value = string.Format( "{0}", xAdresObiekt.YAO_Nazwa?.Trim().Replace( "\n\r", " " ) );
worksheet.Cells[string.Format( "H{0}", lp )].Value = string.Empty;
worksheet.Cells[string.Format( "I{0}", lp )].Value = string.Format( "{0}", xNadajnik.YWNA_Lp );
worksheet.Cells[string.Format( "J{0}", lp )].Value = string.Format( "{0:0.0000000}", xAdresObiekt.YAO_Geo_Lat );
worksheet.Cells[string.Format( "K{0}", lp )].Value = string.Format( "{0:0.0000000}", xAdresObiekt.YAO_Geo_Lng );
worksheet.Cells[string.Format( "L{0}", lp )].Value = string.Format( "{0}", xMontaz.YWU_Miejsce_Zabudowa?.Trim() );
worksheet.Cells[string.Format( "M{0}", lp )].Value = string.Empty;
worksheet.Cells[string.Format( "N{0}", lp )].Value = string.Format( "{0}", xAdresObiekt.YAO_Kod_Poczta?.Trim() );
worksheet.Cells[string.Format( "O{0}", lp )].Value = string.Empty;
}
using ( FileStream stream = new FileStream( tbPlikEksport.Text, FileMode.Create, FileAccess.ReadWrite ) ) {
workbook.SaveDocument( stream, DocumentFormat.OpenXml );
}
}
以上是关于csharp export do excela z grida#c #devexpress #spreadsheet #devexpress #xaf的主要内容,如果未能解决你的问题,请参考以下文章