| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Drawing;
- using System.Drawing.Printing;
- using System.IO;
- using System.Threading;
- using System.Windows.Forms;
- using Dongke.IBOSS.Framework.Controls;
- /*using iTextSharp.text;
- using iTextSharp.text.pdf;*/
- using Microsoft.VisualBasic;
- using Microsoft.VisualBasic.CompilerServices;
- using Microsoft.VisualBasic.FileIO;
- using NPOI.XSSF.UserModel;
- using NPOI.SS.UserModel;
- using Curtain.Log;
- namespace Dongke.IBOSS.PRD.Framework.Controls
- {
- public class MES_Common
- {
- /* private class testevent : IPdfPageEvent
- {
- private PdfContentByte cb;
- private PdfTemplate template;
- public void OnChapter(PdfWriter writer, Document document, float paragraphPosition, Paragraph title)
- {
- }
- public void OnChapterEnd(PdfWriter writer, Document document, float paragraphPosition)
- {
- }
- public void OnCloseDocument(PdfWriter writer, Document document)
- {
- ((PdfContentByte)template).BeginText();
- ((PdfContentByte)template).SetFontAndSize(BaseFont.CreateFont(), 10f);
- ((PdfContentByte)template).SetTextMatrix(0f, 0f);
- ((PdfContentByte)template).ShowText(Conversions.ToString(checked(writer.PageNumber - 1)));
- ((PdfContentByte)template).EndText();
- }
- public void OnEndPage(PdfWriter writer, Document document)
- {
- string text = " - " + writer.PageNumber;
- BaseFont val = BaseFont.CreateFont();
- float widthPoint = val.GetWidthPoint("1", 10f);
- Rectangle pageSize = document.PageSize;
- cb.SetRGBColorFill(100, 100, 100);
- cb.BeginText();
- cb.SetFontAndSize(val, 10f);
- cb.SetTextMatrix(document.LeftMargin + (document.PageSize.Width - document.RightMargin - document.LeftMargin) / 2f, pageSize.GetBottom(document.BottomMargin) - document.BottomMargin / 3f);
- cb.ShowText(text);
- cb.EndText();
- cb.AddTemplate(template, document.LeftMargin - widthPoint + (document.PageSize.Width - document.RightMargin - document.LeftMargin) / 2f, pageSize.GetBottom(document.BottomMargin) - document.BottomMargin / 3f);
- }
- public void OnGenericTag(PdfWriter writer, Document document, Rectangle rect, string text)
- {
- }
- public void OnOpenDocument(PdfWriter writer, Document document)
- {
- cb = writer.DirectContent;
- template = cb.CreateTemplate(50f, 50f);
- }
- public void OnParagraph(PdfWriter writer, Document document, float paragraphPosition)
- {
- }
- public void OnParagraphEnd(PdfWriter writer, Document document, float paragraphPosition)
- {
- }
- public void OnSection(PdfWriter writer, Document document, float paragraphPosition, int depth, Paragraph title)
- {
- }
- public void OnSectionEnd(PdfWriter writer, Document document, float paragraphPosition)
- {
- }
- public void OnStartPage(PdfWriter writer, Document document)
- {
- }
- }
- */
- private static MES_Common _instance;
- /*private Document mydoc;
- private PdfWriter mywriter;*/
- private float _paperwidth;
- private float _paperheight;
- private bool _paperlandscape;
- private Margins _margin;
- private float myratio;
- private bool _repeatheader;
- private bool disposedValue;
- public static MES_Common Instance
- {
- get
- {
- if (_instance == null)
- {
- _instance = new MES_Common();
- }
- return _instance;
- }
- }
- public bool RepeatHeader
- {
- get
- {
- return _repeatheader;
- }
- set
- {
- _repeatheader = value;
- }
- }
- public Margins PaperMargin
- {
- get
- {
- return _margin;
- }
- set
- {
- _margin = value;
- }
- }
- public float PaperWidth
- {
- get
- {
- return _paperwidth;
- }
- set
- {
- _paperwidth = value;
- }
- }
- public float PaperHeight
- {
- get
- {
- return _paperheight;
- }
- set
- {
- if (value > 0f)
- {
- _paperheight = value;
- }
- }
- }
- public bool PaperLandScape
- {
- get
- {
- return _paperlandscape;
- }
- set
- {
- _paperlandscape = value;
- }
- }
- private MES_Common()
- {
- }
- public bool ExportExcel(DataGridView mydgv, TreeView columnheadertree, Font titlefont, string title, string FileName, Font tableheaderfont, string Tableheader, Font tablefooterfont, string TableFooter, string sheetname, bool isopenfile, bool isshowprogress, bool isTopNodeFill)
- {
- checked
- {
- bool result;
- if (mydgv == null)
- {
- result = false;
- }
- else
- {
- if (titlefont == null)
- {
- titlefont = new Font("黑体", 18f, FontStyle.Bold);
- }
- if (tableheaderfont == null)
- {
- tableheaderfont = new Font("宋体", 12f);
- }
- if (tablefooterfont == null)
- {
- tablefooterfont = new Font("宋体", 12f);
- }
- progressexcel progressexcel = null;
- Module1.G_CancelExportDGVToExcel = false;
- if (isshowprogress)
- {
- progressexcel = new progressexcel();
- progressexcel.TopMost = true;
- progressexcel.Visible = true;
- }
- Ruler ruler = new Ruler();
- try
- {
- if (isshowprogress)
- {
- progressexcel.Label1.Text = "正在做导出前的准备,请稍侯……";
- progressexcel.ProgressBar1.Value = 0;
- Application.DoEvents();
- }
- int columnCount = mydgv.ColumnCount;
- int[] array = new int[columnCount - 1 + 1];
- int[] array2 = new int[columnCount - 1 + 1];
- int num = 0;
- int num2 = 0;
- int num3 = columnCount - 1;
- for (int i = num2; i <= num3; i++)
- {
- array[i] = i;
- array2[i] = mydgv.Columns[i].DisplayIndex;
- if (mydgv.Columns[i].Visible)
- {
- num++;
- }
- }
- if (num <= 0)
- {
- if (isshowprogress)
- {
- progressexcel.Close();
- progressexcel.Dispose();
- }
- result = true;
- }
- else
- {
- Array.Sort(array2, array);
- int[] array3 = new int[num - 1 + 1];
- int num4 = 0;
- int num5 = 0;
- int num6 = columnCount - 1;
- for (int j = num5; j <= num6; j++)
- {
- if (mydgv.Columns[array[j]].Visible)
- {
- array3[num4] = array[j];
- num4++;
- }
- }
- DGVtoExcel.w_ZDYcolors = 8;
- int endcol = num - 1;
- SaveFileDialog saveFileDialog = new SaveFileDialog();
- saveFileDialog.Title = "请选择要导出Excel文件的路径和文件名";
- saveFileDialog.AddExtension = true;
- saveFileDialog.OverwritePrompt = false;
- //saveFileDialog.DefaultExt = "xls";
- //saveFileDialog.Filter = "97-2003 Excel文件(*.xls)|*.xls|所有文件(*.*)|*.*";
- saveFileDialog.DefaultExt = "xlsx";
- saveFileDialog.Filter = "Excel文件(*.xlsx)|*.xlsx|所有文件(*.*)|*.*";
- saveFileDialog.FileName = FileName;
- if (isshowprogress)
- {
- progressexcel.Visible = false;
- }
- if (saveFileDialog.ShowDialog() == DialogResult.Cancel)
- {
- if (isshowprogress)
- {
- progressexcel.Close();
- progressexcel.Dispose();
- }
- saveFileDialog.Dispose();
- return false;
- }
- FileName = saveFileDialog.FileName;
- saveFileDialog.Dispose();
- if (isshowprogress)
- {
- progressexcel.Visible = true;
- }
- DGVtoExcel.w_font = null;
- DGVtoExcel.w_ifont = null;
- DGVtoExcel.w_Cellstyle = null;
- DGVtoExcel.w_iCellstyle = null;
- DGVtoExcel.w_color = null;
- if (MyProject.Computer.FileSystem.FileExists(FileName))
- {
- if (isshowprogress)
- {
- progressexcel.Visible = false;
- }
- switch (Interaction.MsgBox("选择的文件【" + FileName + "】已经存在,您确定要覆盖原来的文件吗?注意:覆盖原文件后,原文件中的全部数据都将丢失!\r\n单击[是]按钮,将覆盖原文件,单击[否]按钮,导出数据将以追加的形式添加到文件中,单击[取消]按钮将取消导出", MsgBoxStyle.YesNoCancel | MsgBoxStyle.Question, "提示信息"))
- {
- case MsgBoxResult.Cancel:
- if (isshowprogress)
- {
- progressexcel.Close();
- progressexcel.Dispose();
- }
- return false;
- case MsgBoxResult.Yes:
- try
- {
- MyProject.Computer.FileSystem.DeleteFile(FileName, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
- }
- catch (Exception projectError)
- {
- Logger.Error(projectError, "projectError");
- MessageBox.Show(projectError.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
- ProjectData.SetProjectError(projectError);
- Interaction.MsgBox("数据导出失败,原因是文件【" + FileName + "】无法覆盖,可能该文件正在使用中,请关闭该文件后再试", MsgBoxStyle.Exclamation, "提示信息");
- if (isshowprogress)
- {
- progressexcel.Close();
- progressexcel.Dispose();
- }
- result = false;
- ProjectData.ClearProjectError();
- return result;
- }
- break;
- }
- if (isshowprogress)
- {
- progressexcel.Visible = true;
- }
- }
- XSSFWorkbook hSSFWorkbook;
- if (MyProject.Computer.FileSystem.FileExists(FileName))
- {
- FileStream fileStream;
- try
- {
- fileStream = new FileStream(FileName, FileMode.Open, FileAccess.Read);
- }
- catch (Exception ex)
- {
- Logger.Error(ex, "ex");
- MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
- ProjectData.SetProjectError(ex);
- Exception ex2 = ex;
- if (isshowprogress)
- {
- progressexcel.Close();
- progressexcel.Dispose();
- }
- Interaction.MsgBox("数据导出失败,原因是打开Excel文件〖" + FileName + "〗失败," + ex2.Message, MsgBoxStyle.Exclamation, "提示信息");
- fileStream = null;
- result = false;
- ProjectData.ClearProjectError();
- return result;
- }
- try
- {
- hSSFWorkbook = new XSSFWorkbook(fileStream);
- }
- catch (Exception projectError2)
- {
- Logger.Error(projectError2, "projectError2");
- MessageBox.Show(projectError2.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
- ProjectData.SetProjectError(projectError2);
- if (isshowprogress)
- {
- progressexcel.Close();
- progressexcel.Dispose();
- }
- fileStream.Dispose();
- fileStream = null;
- Interaction.MsgBox("数据导出失败,原因是打开Excel文件〖" + FileName + "〗失败,可能不是有效的Office97-2003 Excel文件格式,因此无法向该文件中追加导出的数据", MsgBoxStyle.Exclamation, "提示信息");
- hSSFWorkbook = null;
- result = false;
- ProjectData.ClearProjectError();
- return result;
- }
- }
- else
- {
- hSSFWorkbook = new XSSFWorkbook();
- }
- string excelNewSheetName = DGVtoExcel.GetExcelNewSheetName(hSSFWorkbook, sheetname);
- XSSFSheet hSSFSheet = (XSSFSheet)hSSFWorkbook.CreateSheet(excelNewSheetName);
- int num7;
- if (Operators.CompareString(title, "", TextCompare: false) == 0)
- {
- num7 = 0;
- }
- else
- {
- DGVtoExcel.SetTitle(hSSFWorkbook, hSSFSheet, 0, 0, 0, endcol, title, titlefont);
- num7 = 1;
- }
- if (Operators.CompareString(Tableheader, "", TextCompare: false) != 0)
- {
- DGVtoExcel.SetTitle(hSSFWorkbook, hSSFSheet, num7, num7, 0, endcol, Tableheader, tableheaderfont);
- num7++;
- }
- DGVtoExcel.w_gridcolor = DGVtoExcel.GetXLColour(hSSFWorkbook, mydgv.GridColor);
- if (mydgv.ColumnHeadersVisible)
- {
- if (columnheadertree == null)
- {
- IRow row = hSSFSheet.CreateRow(num7);
- row.HeightInPoints = Module1.ConvertMmToInch(ruler.ConvertToMM(mydgv.ColumnHeadersHeight, isX: false)) * 72f;
- int num8 = 0;
- int num9 = num - 1;
- for (int k = num8; k <= num9; k++)
- {
- DGVtoExcel.SetCellValue(hSSFSheet, num7, k, mydgv.Columns[array3[k]].HeaderText);
- Font dGVHeaderFont = Module1.GetDGVHeaderFont(mydgv.Columns[array3[k]]);
- Color dGVHeaderBackColor = Module1.GetDGVHeaderBackColor(mydgv.Columns[array3[k]]);
- Color dGVHeaderForeColor = Module1.GetDGVHeaderForeColor(mydgv.Columns[array3[k]]);
- DGVtoExcel.SetCellStyle(hSSFWorkbook, hSSFSheet, num7, k, leftborder: true, rightborder: true, topborder: true, bottomborder: true, StringAlignment.Center, StringAlignment.Center, dGVHeaderFont, dGVHeaderBackColor, dGVHeaderForeColor, needwrap: false);
- }
- }
- else
- {
- mytree mytree = new mytree(columnheadertree, mydgv);
- int leves = mytree.GetLeves();
- int num10 = 1;
- int num11 = leves;
- for (int l = num10; l <= num11; l++)
- {
- IRow row2 = hSSFSheet.CreateRow(num7 + l - 1);
- row2.HeightInPoints = Module1.ConvertMmToInch(ruler.ConvertToMM((float)((double)mydgv.ColumnHeadersHeight / (double)leves), isX: false)) * 72f;
- }
- int num12 = 1;
- int num13 = leves;
- bool flag = true;
- for (int m = num12; m <= num13; m++)
- {
- if (m != 1)
- {
- num7++;
- }
- int num14 = 0;
- int num15 = num - 1;
- for (int n = num14; n <= num15; n++)
- {
- string nodeText = mytree.GetNodeText(array3[n], m);
- int cellHeightLevels = mytree.GetCellHeightLevels(array3[n], m, isTopNodeFill, out flag);
- int cellWidthCols = mytree.GetCellWidthCols(array3[n], m);
- if (unchecked(cellHeightLevels == 0 || cellWidthCols == 0))
- {
- continue;
- }
- Font font = mytree.GetNodeFont(array3[n], m);
- if (font == null)
- {
- font = Module1.GetDGVHeaderFont(mydgv.Columns[array3[n]]);
- }
- Color forcolor = mytree.GetNodeForeColor(array3[n], m);
- if (forcolor.IsEmpty)
- {
- forcolor = Module1.GetDGVHeaderForeColor(mydgv.Columns[array3[n]]);
- }
- Color bkcolor = mytree.GetNodeBackColor(array3[n], m);
- if (bkcolor.IsEmpty)
- {
- bkcolor = Module1.GetDGVHeaderBackColor(mydgv.Columns[array3[n]]);
- }
- if (unchecked(cellWidthCols == 1 && cellHeightLevels == 1))
- {
- int num16 = num7;
- if (!flag)
- {
- num16++;
- }
- DGVtoExcel.SetCellValue(hSSFSheet, num16, n, nodeText);
- DGVtoExcel.SetCellStyle(hSSFWorkbook, hSSFSheet, num16, n, leftborder: true, rightborder: true, topborder: true, bottomborder: true, StringAlignment.Center, StringAlignment.Center, font, bkcolor, forcolor, needwrap: false);
- continue;
- }
- DGVtoExcel.SetCellValue(hSSFSheet, num7, n, nodeText);
- DGVtoExcel.SetCellStyle(hSSFWorkbook, hSSFSheet, num7, n, leftborder: true, rightborder: true, topborder: true, bottomborder: true, StringAlignment.Center, StringAlignment.Center, font, bkcolor, forcolor, needwrap: false);
- int num17 = num7;
- int num18 = num7 + cellHeightLevels - 1;
- for (int num19 = num17; num19 <= num18; num19++)
- {
- int num20 = n;
- int num21 = n + cellWidthCols - 1;
- for (int num22 = num20; num22 <= num21; num22++)
- {
- if (unchecked(num19 != num7 || num22 != n))
- {
- DGVtoExcel.SetCellBorder(hSSFWorkbook, hSSFSheet, num19, num22, leftborder: true, rightborder: true, topborder: true, bottomborder: true);
- }
- }
- }
- DGVtoExcel.SetMergeCell(hSSFSheet, num7, n, num7 + cellHeightLevels - 1, n + cellWidthCols - 1);
- }
- }
- mytree.Dispose();
- }
- num7++;
- }
- int num23 = 1;
- int num24 = 0;
- int num25 = 0;
- int num26 = 0;
- int num27 = 0;
- int num28 = 1;
- int num29 = 0;
- int num30 = mydgv.RowCount - 1;
- for (int num31 = num29; num31 <= num30; num31++)
- {
- IRow row3 = hSSFSheet.CreateRow(num7 + num31);
- row3.HeightInPoints = Module1.ConvertMmToInch(ruler.ConvertToMM(mydgv.Rows[num31].Height, isX: false)) * 72f;
- if (!mydgv.Rows[num31].Visible)
- {
- row3.ZeroHeight = true;
- }
- if (num31 + num7 == 1048575)
- {
- break;
- }
- }
- int num32 = 0;
- int num33 = 0;
- if (isshowprogress)
- {
- progressexcel.ProgressBar1.Maximum = mydgv.RowCount;
- }
- int num34 = 0;
- int num35 = mydgv.RowCount - 1;
- for (int num36 = num34; num36 <= num35; num36++)
- {
- bool flag2 = false;
- if (isshowprogress)
- {
- progressexcel.Label1.Text = "正在导出第〖" + Conversions.ToString(num36 + 1) + "〗条记录,共〖" + Conversions.ToString(mydgv.RowCount) + "〗条记录,已完成〖" + Strings.Format((double)(num36 + 1) / (double)mydgv.RowCount, "###.##%") + "〗";
- progressexcel.ProgressBar1.Value = num36 + 1;
- Application.DoEvents();
- }
- if (Module1.G_CancelExportDGVToExcel)
- {
- break;
- }
- int num37 = 0;
- int num38 = num - 1;
- for (num4 = num37; num4 <= num38; num4++)
- {
- int num39;
- if (mydgv.Columns[array3[num4]].ValueType == null)
- {
- num39 = 0;
- }
- else
- {
- switch (Strings.Left(mydgv.Columns[array3[num4]].ValueType.Name.ToUpper(), 3))
- {
- case "STR":
- num39 = 0;
- break;
- case "INT":
- case "DEC":
- num39 = 1;
- flag2 = false;
- break;
- case "DAT":
- num39 = 2;
- break;
- case "BOO":
- num39 = 3;
- flag2 = false;
- break;
- default:
- num39 = 0;
- break;
- }
- }
- num28 = 1;
- num23 = 1;
- num26 = 0;
- num24 = 0;
- num27 = 0;
- num26 = 0;
- num24 = 0;
- num25 = 0;
- string text = Conversions.ToString(mydgv.Rows[num36].Cells[array3[num4]].Tag);
- switch (text)
- {
- default:
- {
- float mywidth = 0f;
- float num40 = 9f;
- int firstcolumn = 0;
- int firstrow = 0;
- int firstc = 0;
- int firstr = 0;
- switch (text)
- {
- default:
- num28 = 1;
- num23 = 1;
- break;
- case "合并":
- case "左上合并":
- case "左下合并":
- case "右上合并":
- case "右下合并":
- case "上边合并":
- case "下边合并":
- case "左边合并":
- case "右边合并":
- mymerge.GetHVMergeWidthAndHeight(mydgv, array3[num4], num36, ref mywidth, ref num40, ref num27, ref num26, ref num24, ref num25, ref firstcolumn, ref firstrow, ref firstc, ref firstr);
- num28 = num26 + num27 + 1;
- num23 = num24 + num25 + 1;
- break;
- case "水平合并":
- case "#水平合并#":
- case "左合并":
- case "右合并":
- mywidth = (int)Math.Round(mymerge.GetHMergeWidth(mydgv, array3[num4], num36, ref num28, ref num26, ref num27, ref firstcolumn, ref firstc, iscancheckheight: true));
- break;
- }
- break;
- }
- case "垂直合并":
- case "#垂直合并#":
- case "上合并":
- case "下合并":
- {
- int firstrow = 0;
- int firstr = 0;
- float num40 = mymerge.GetVMergeHeight(mydgv, array3[num4], num36, ref num23, ref num25, ref num24, ref firstrow, ref firstr);
- break;
- }
- }
- if (unchecked(num26 > 0 || num24 > 0))
- {
- continue;
- }
- if (Operators.CompareString(Versioned.TypeName(mydgv.Columns[array3[num4]]), "DataGridViewImageColumn", TextCompare: false) == 0)
- {
- if (mydgv.Rows[num36].Cells[array3[num4]].Value != null)
- {
- Image img = (Image)mydgv.Rows[num36].Cells[array3[num4]].FormattedValue;
- byte[] byteByImage = DGVtoExcel.GetByteByImage(img);
- int pictureIndex = hSSFWorkbook.AddPicture(byteByImage, PictureType.JPEG);
- IDrawing drawing = hSSFSheet.CreateDrawingPatriarch();
- XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, num4, num7 + num36, num4 + 1, num7 + num36 + 1);
- drawing.CreatePicture(anchor, pictureIndex);
- }
- }
- else if (Operators.CompareString(Versioned.TypeName(mydgv.Columns[array3[num4]]), "DataGridViewCheckBoxColumn", TextCompare: false) == 0)
- {
- if (mydgv.Rows[num36].Cells[array3[num4]].Value != null && Conversions.ToBoolean(mydgv.Rows[num36].Cells[array3[num4]].Value))
- {
- DGVtoExcel.SetCellValue(hSSFSheet, num7 + num36, num4, "√");
- }
- flag2 = false;
- }
- else
- {
- string text2 = Conversions.ToString(mydgv.Rows[num36].Cells[array3[num4]].FormattedValue) ?? "";
- flag2 = Strings.InStr(text2, "\r\n") > 0;
- switch (num39)
- {
- case 1:
- if (Versioned.IsNumeric(text2))
- {
- DGVtoExcel.SetCellValue(hSSFSheet, num7 + num36, num4, Conversions.ToDouble(text2));
- }
- else
- {
- DGVtoExcel.SetCellValue(hSSFSheet, num7 + num36, num4, text2);
- }
- break;
- case 2:
- DGVtoExcel.SetCellValue(hSSFSheet, num7 + num36, num4, text2);
- break;
- default:
- DGVtoExcel.SetCellValue(hSSFSheet, num7 + num36, num4, text2);
- break;
- }
- }
- DataGridViewCellStyle dGVCellStyle = Module1.GetDGVCellStyle(mydgv.Rows[num36].Cells[array3[num4]]);
- DataGridViewContentAlignment alignment = dGVCellStyle.Alignment;
- StringAlignment valign = StringAlignment.Center;
- StringAlignment halign = StringAlignment.Center;
- switch (alignment)
- {
- case DataGridViewContentAlignment.BottomCenter:
- valign = StringAlignment.Far;
- halign = StringAlignment.Center;
- break;
- case DataGridViewContentAlignment.MiddleCenter:
- valign = StringAlignment.Center;
- halign = StringAlignment.Center;
- break;
- case DataGridViewContentAlignment.TopCenter:
- valign = StringAlignment.Near;
- halign = StringAlignment.Center;
- break;
- case DataGridViewContentAlignment.BottomLeft:
- valign = StringAlignment.Far;
- halign = StringAlignment.Near;
- break;
- case DataGridViewContentAlignment.MiddleLeft:
- valign = StringAlignment.Center;
- halign = StringAlignment.Near;
- break;
- case DataGridViewContentAlignment.TopLeft:
- valign = StringAlignment.Near;
- halign = StringAlignment.Near;
- break;
- case DataGridViewContentAlignment.BottomRight:
- valign = StringAlignment.Far;
- halign = StringAlignment.Far;
- break;
- case DataGridViewContentAlignment.MiddleRight:
- valign = StringAlignment.Center;
- halign = StringAlignment.Far;
- break;
- case DataGridViewContentAlignment.TopRight:
- valign = StringAlignment.Near;
- halign = StringAlignment.Far;
- break;
- }
- if (string.Concat(mydgv.Rows[num36].Cells[array3[num4]].Tag).Contains("合并"))
- {
- valign = StringAlignment.Center;
- halign = StringAlignment.Center;
- }
- if (!flag2 && dGVCellStyle.WrapMode == DataGridViewTriState.True)
- {
- flag2 = true;
- }
- Color dGVCellBackColor = Module1.GetDGVCellBackColor(mydgv.Rows[num36].Cells[array3[num4]]);
- Color dGVCellForeColor = Module1.GetDGVCellForeColor(mydgv.Rows[num36].Cells[array3[num4]]);
- DGVtoExcel.SetCellStyle(hSSFWorkbook, hSSFSheet, num7 + num36, num4, leftborder: true, rightborder: true, topborder: true, bottomborder: true, halign, valign, Module1.GetDGVCellFont(mydgv.Rows[num36].Cells[array3[num4]]), dGVCellBackColor, dGVCellForeColor, flag2);
- if (unchecked(num28 == 1 && num23 == 1))
- {
- continue;
- }
- int num41 = num7 + num36;
- int num42 = num7 + num36 + num25;
- for (int num43 = num41; num43 <= num42; num43++)
- {
- int num44 = num4;
- int num45 = num4 + num27;
- for (int num46 = num44; num46 <= num45; num46++)
- {
- unchecked
- {
- if (num43 != checked(num7 + num36) || num46 != num4)
- {
- DGVtoExcel.SetCellBorder(hSSFWorkbook, hSSFSheet, num43, num46, leftborder: true, rightborder: true, topborder: true, bottomborder: true);
- }
- }
- }
- }
- DGVtoExcel.SetMergeCell(hSSFSheet, num7 + num36, num4, num7 + num36 + num25, num4 + num27);
- num4 += num27;
- }
- if (!((num36 + num7 == 1048575) & (num36 != mydgv.RowCount - 1)))
- {
- continue;
- }
- int num47 = 0;
- int num48 = num - 1;
- for (int num49 = num47; num49 <= num48; num49++)
- {
- hSSFSheet.SetColumnWidth(num49, (int)Math.Round(Math.Ceiling((double)mydgv.Columns[array3[num49]].Width / 8.0) * 256.0));
- }
- num32++;
- excelNewSheetName = DGVtoExcel.GetExcelNewSheetName(hSSFWorkbook, sheetname);
- hSSFSheet = (XSSFSheet)hSSFWorkbook.CreateSheet(excelNewSheetName);
- num33 = 1;
- int num50 = num36 + 1;
- int num51 = mydgv.RowCount - 1;
- for (num4 = num50; num4 <= num51; num4++)
- {
- IRow row4 = hSSFSheet.CreateRow(num33 - 1);
- if (!mydgv.Rows[num4].Visible)
- {
- row4.ZeroHeight = true;
- }
- row4.HeightInPoints = Module1.ConvertMmToInch(ruler.ConvertToMM(mydgv.Rows[num4].Height, isX: false)) * 72f;
- if (num33 == 1048576)
- {
- break;
- }
- num33++;
- }
- num7 = -num36 - 1;
- }
- num7 = ((num33 != 0) ? (num33 - 1) : (num7 + mydgv.RowCount));
- if (Operators.CompareString(TableFooter, "", TextCompare: false) != 0)
- {
- DGVtoExcel.SetTitle(hSSFWorkbook, hSSFSheet, num7, num7, 0, endcol, TableFooter, tablefooterfont);
- }
- DGVtoExcel.w_font = null;
- DGVtoExcel.w_ifont = null;
- DGVtoExcel.w_Cellstyle = null;
- DGVtoExcel.w_iCellstyle = null;
- DGVtoExcel.w_color = null;
- int num52 = 0;
- int num53 = num - 1;
- for (int num54 = num52; num54 <= num53; num54++)
- {
- hSSFSheet.SetColumnWidth(num54, (int)Math.Round(Math.Ceiling((double)mydgv.Columns[array3[num54]].Width / 8.0) * 256.0));
- }
- ruler.Dispose();
- ruler = null;
- if (isshowprogress)
- {
- progressexcel.Close();
- progressexcel.Dispose();
- }
- hSSFWorkbook.SetActiveSheet(hSSFWorkbook.GetSheetIndex(excelNewSheetName));
- if (!DGVtoExcel.WriteToFile(hSSFWorkbook, FileName))
- {
- hSSFWorkbook = null;
- result = false;
- }
- else
- {
- hSSFWorkbook = null;
- if (isopenfile && Interaction.MsgBox("导出的Excel文件已保存到【" + FileName + " 】\r\n您是否要立即打开这个文件以查看其内容?", MsgBoxStyle.YesNoCancel, "提示信息") == MsgBoxResult.Yes)
- {
- try
- {
- Process.Start(FileName);
- }
- catch (Exception projectError3)
- {
- Logger.Error(projectError3, "projectError3");
- MessageBox.Show(projectError3.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
- ProjectData.SetProjectError(projectError3);
- try
- {
- Thread.Sleep(100);
- Process.Start(FileName);
- }
- catch (Exception projectError4)
- {
- Logger.Error(projectError4, "projectError4");
- MessageBox.Show(projectError4.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
- ProjectData.SetProjectError(projectError4);
- ProjectData.ClearProjectError();
- }
- ProjectData.ClearProjectError();
- }
- }
- result = true;
- }
- }
- }
- catch (Exception projectError5)
- {
- Logger.Error(projectError5, "projectError5");
- MessageBox.Show(projectError5.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
- ProjectData.SetProjectError(projectError5);
- if (isshowprogress)
- {
- progressexcel.Close();
- progressexcel.Dispose();
- }
- try
- {
- ruler.Dispose();
- ruler = null;
- }
- catch (Exception projectError6)
- {
- Logger.Error(projectError6, "projectError6");
- MessageBox.Show(projectError6.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
- ProjectData.SetProjectError(projectError6);
- ProjectData.ClearProjectError();
- }
- if (Operators.CompareString(FileName, "", TextCompare: false) == 0)
- {
- result = DGVtoExcel.myNewDGVtoExcel(mydgv, FileName, title, Tableheader, TableFooter, isopenfile: true);
- ProjectData.ClearProjectError();
- }
- else
- {
- result = DGVtoExcel.myNewDGVtoExcel(mydgv, FileName, title, Tableheader, TableFooter, isopenfile: false);
- ProjectData.ClearProjectError();
- }
- }
- }
- return result;
- }
- }
- public bool ExportExcel(List<DataGridView> mydgvs, List<TreeView> columnheadertrees, Font titlefont, string title, string FileName, Font tableheaderfont, string Tableheader, Font tablefooterfont, string TableFooter, List<string> sheetnames, bool isopenfile, bool isshowprogress, bool isshowSheetTitle, bool isTopNodeFill)
- {
- bool result = true;
- checked
- {
- if (mydgvs == null || mydgvs.Count == 0 || sheetnames == null || sheetnames.Count == 0 || mydgvs.Count != sheetnames.Count)
- {
- result = false;
- }
- else
- {
- if (columnheadertrees != null && columnheadertrees.Count > 0 && mydgvs.Count != columnheadertrees.Count)
- {
- return false;
- }
- int num = 0;
- int num2 = 0;
- for (int i = 0; i < mydgvs.Count; i++)
- {
- num += mydgvs[i].Rows.Count;
- }
- if (titlefont == null)
- {
- titlefont = new Font("黑体", 18f, FontStyle.Bold);
- }
- if (tableheaderfont == null)
- {
- tableheaderfont = new Font("宋体", 12f);
- }
- if (tablefooterfont == null)
- {
- tablefooterfont = new Font("宋体", 12f);
- }
- progressexcel progressexcel = null;
- Module1.G_CancelExportDGVToExcel = false;
- if (isshowprogress)
- {
- progressexcel = new progressexcel();
- progressexcel.TopMost = true;
- progressexcel.Visible = true;
- }
- Ruler ruler = new Ruler();
- try
- {
- if (isshowprogress)
- {
- progressexcel.Label1.Text = "正在做导出前的准备,请稍侯……";
- progressexcel.ProgressBar1.Value = 0;
- Application.DoEvents();
- }
- bool flag = false;
- DataGridView dataGridView = null;
- TreeView treeView = null;
- XSSFWorkbook hSSFWorkbook = null;
- string empty = string.Empty;
- for (int j = 0; j < mydgvs.Count; j++)
- {
- empty = sheetnames[j];
- dataGridView = mydgvs[j];
- if (columnheadertrees != null && columnheadertrees.Count > 0)
- {
- treeView = columnheadertrees[j];
- }
- int columnCount = dataGridView.ColumnCount;
- int[] array = new int[columnCount - 1 + 1];
- int[] array2 = new int[columnCount - 1 + 1];
- int num3 = 0;
- int num4 = 0;
- int num5 = columnCount - 1;
- for (int k = num4; k <= num5; k++)
- {
- array[k] = k;
- array2[k] = dataGridView.Columns[k].DisplayIndex;
- if (dataGridView.Columns[k].Visible)
- {
- num3++;
- }
- }
- if (num3 <= 0)
- {
- if (isshowprogress)
- {
- progressexcel.Close();
- progressexcel.Dispose();
- }
- result = true;
- }
- else
- {
- Array.Sort(array2, array);
- int[] array3 = new int[num3 - 1 + 1];
- int num6 = 0;
- int num7 = 0;
- int num8 = columnCount - 1;
- for (int l = num7; l <= num8; l++)
- {
- if (dataGridView.Columns[array[l]].Visible)
- {
- array3[num6] = array[l];
- num6++;
- }
- }
- DGVtoExcel.w_ZDYcolors = 8;
- int endcol = num3 - 1;
- if (!flag)
- {
- SaveFileDialog saveFileDialog = new SaveFileDialog();
- saveFileDialog.Title = "请选择要导出Excel文件的路径和文件名";
- saveFileDialog.AddExtension = true;
- saveFileDialog.OverwritePrompt = false;
- saveFileDialog.DefaultExt = "xls";
- saveFileDialog.Filter = "97-2003 Excel文件(*.xls)|*.xls|所有文件(*.*)|*.*";
- saveFileDialog.FileName = FileName;
- if (isshowprogress)
- {
- progressexcel.Visible = false;
- }
- if (saveFileDialog.ShowDialog() == DialogResult.Cancel)
- {
- if (isshowprogress)
- {
- progressexcel.Close();
- progressexcel.Dispose();
- }
- saveFileDialog.Dispose();
- result = false;
- return result;
- }
- FileName = saveFileDialog.FileName;
- saveFileDialog.Dispose();
- if (isshowprogress)
- {
- progressexcel.Visible = true;
- }
- DGVtoExcel.w_font = null;
- DGVtoExcel.w_ifont = null;
- DGVtoExcel.w_Cellstyle = null;
- DGVtoExcel.w_iCellstyle = null;
- DGVtoExcel.w_color = null;
- if (MyProject.Computer.FileSystem.FileExists(FileName))
- {
- if (isshowprogress)
- {
- progressexcel.Visible = false;
- }
- switch (Interaction.MsgBox("选择的文件【" + FileName + "】已经存在,您确定要覆盖原来的文件吗?注意:覆盖原文件后,原文件中的全部数据都将丢失!\r\n单击[是]按钮,将覆盖原文件,单击[否]按钮,导出数据将以追加的形式添加到文件中,单击[取消]按钮将取消导出", MsgBoxStyle.YesNoCancel | MsgBoxStyle.Question, "提示信息"))
- {
- case MsgBoxResult.Cancel:
- if (isshowprogress)
- {
- progressexcel.Close();
- progressexcel.Dispose();
- }
- result = false;
- return result;
- case MsgBoxResult.Yes:
- try
- {
- MyProject.Computer.FileSystem.DeleteFile(FileName, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
- }
- catch (Exception projectError)
- {
- Logger.Error(projectError, "projectError");
- MessageBox.Show(projectError.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
- ProjectData.SetProjectError(projectError);
- Interaction.MsgBox("数据导出失败,原因是文件【" + FileName + "】无法覆盖,可能该文件正在使用中,请关闭该文件后再试", MsgBoxStyle.Exclamation, "提示信息");
- if (isshowprogress)
- {
- progressexcel.Close();
- progressexcel.Dispose();
- }
- result = false;
- ProjectData.ClearProjectError();
- return result;
- }
- break;
- }
- if (isshowprogress)
- {
- progressexcel.Visible = true;
- }
- }
- if (MyProject.Computer.FileSystem.FileExists(FileName))
- {
- FileStream fileStream;
- try
- {
- fileStream = new FileStream(FileName, FileMode.Open, FileAccess.Read);
- }
- catch (Exception ex)
- {
- Logger.Error(ex, "list-ex");
- MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
- ProjectData.SetProjectError(ex);
- Exception ex2 = ex;
- if (isshowprogress)
- {
- progressexcel.Close();
- progressexcel.Dispose();
- }
- Interaction.MsgBox("数据导出失败,原因是打开Excel文件〖" + FileName + "〗失败," + ex2.Message, MsgBoxStyle.Exclamation, "提示信息");
- fileStream = null;
- result = false;
- ProjectData.ClearProjectError();
- return result;
- }
- try
- {
- hSSFWorkbook = new XSSFWorkbook(fileStream);
- }
- catch (Exception projectError2)
- {
- Logger.Error(projectError2, "list-projectError2");
- MessageBox.Show(projectError2.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
- ProjectData.SetProjectError(projectError2);
- if (isshowprogress)
- {
- progressexcel.Close();
- progressexcel.Dispose();
- }
- fileStream.Dispose();
- fileStream = null;
- Interaction.MsgBox("数据导出失败,原因是打开Excel文件〖" + FileName + "〗失败,可能不是有效的Office97-2003 Excel文件格式,因此无法向该文件中追加导出的数据", MsgBoxStyle.Exclamation, "提示信息");
- hSSFWorkbook = null;
- result = false;
- ProjectData.ClearProjectError();
- return result;
- }
- }
- else
- {
- hSSFWorkbook = new XSSFWorkbook();
- }
- flag = true;
- }
- string excelNewSheetName = DGVtoExcel.GetExcelNewSheetName(hSSFWorkbook, empty);
- XSSFSheet hSSFSheet = (XSSFSheet)hSSFWorkbook.CreateSheet(excelNewSheetName);
- int num9;
- if (Operators.CompareString(title, "", TextCompare: false) == 0)
- {
- num9 = 0;
- }
- else if (isshowSheetTitle)
- {
- DGVtoExcel.SetTitle(hSSFWorkbook, hSSFSheet, 0, 0, 0, endcol, empty, titlefont);
- num9 = 1;
- }
- else
- {
- num9 = 0;
- }
- if (Operators.CompareString(Tableheader, "", TextCompare: false) != 0)
- {
- DGVtoExcel.SetTitle(hSSFWorkbook, hSSFSheet, num9, num9, 0, endcol, Tableheader, tableheaderfont);
- num9++;
- }
- DGVtoExcel.w_gridcolor = DGVtoExcel.GetXLColour(hSSFWorkbook, dataGridView.GridColor);
- if (dataGridView.ColumnHeadersVisible)
- {
- if (treeView == null)
- {
- IRow row = hSSFSheet.CreateRow(num9);
- row.HeightInPoints = Module1.ConvertMmToInch(ruler.ConvertToMM(dataGridView.ColumnHeadersHeight, isX: false)) * 72f;
- int num10 = 0;
- int num11 = num3 - 1;
- for (int m = num10; m <= num11; m++)
- {
- DGVtoExcel.SetCellValue(hSSFSheet, num9, m, dataGridView.Columns[array3[m]].HeaderText);
- Font dGVHeaderFont = Module1.GetDGVHeaderFont(dataGridView.Columns[array3[m]]);
- Color dGVHeaderBackColor = Module1.GetDGVHeaderBackColor(dataGridView.Columns[array3[m]]);
- Color dGVHeaderForeColor = Module1.GetDGVHeaderForeColor(dataGridView.Columns[array3[m]]);
- DGVtoExcel.SetCellStyle(hSSFWorkbook, hSSFSheet, num9, m, leftborder: true, rightborder: true, topborder: true, bottomborder: true, StringAlignment.Center, StringAlignment.Center, dGVHeaderFont, dGVHeaderBackColor, dGVHeaderForeColor, needwrap: false);
- }
- }
- else
- {
- mytree mytree = new mytree(treeView, dataGridView);
- int leves = mytree.GetLeves();
- int num12 = 1;
- int num13 = leves;
- for (int n = num12; n <= num13; n++)
- {
- IRow row2 = hSSFSheet.CreateRow(num9 + n - 1);
- row2.HeightInPoints = Module1.ConvertMmToInch(ruler.ConvertToMM((float)((double)dataGridView.ColumnHeadersHeight / (double)leves), isX: false)) * 72f;
- }
- int num14 = 1;
- int num15 = leves;
- bool flag2 = true;
- for (int num16 = num14; num16 <= num15; num16++)
- {
- if (num16 != 1)
- {
- num9++;
- }
- int num17 = 0;
- int num18 = num3 - 1;
- for (int num19 = num17; num19 <= num18; num19++)
- {
- string nodeText = mytree.GetNodeText(array3[num19], num16);
- int cellHeightLevels = mytree.GetCellHeightLevels(array3[num19], num16, isTopNodeFill, out flag2);
- int cellWidthCols = mytree.GetCellWidthCols(array3[num19], num16);
- if (unchecked(cellHeightLevels == 0 || cellWidthCols == 0))
- {
- continue;
- }
- Font font = mytree.GetNodeFont(array3[num19], num16);
- if (font == null)
- {
- font = Module1.GetDGVHeaderFont(dataGridView.Columns[array3[num19]]);
- }
- Color forcolor = mytree.GetNodeForeColor(array3[num19], num16);
- if (forcolor.IsEmpty)
- {
- forcolor = Module1.GetDGVHeaderForeColor(dataGridView.Columns[array3[num19]]);
- }
- Color bkcolor = mytree.GetNodeBackColor(array3[num19], num16);
- if (bkcolor.IsEmpty)
- {
- bkcolor = Module1.GetDGVHeaderBackColor(dataGridView.Columns[array3[num19]]);
- }
- if (unchecked(cellWidthCols == 1 && cellHeightLevels == 1))
- {
- int num20 = num9;
- if (!flag2)
- {
- num20++;
- }
- DGVtoExcel.SetCellValue(hSSFSheet, num20, num19, nodeText);
- DGVtoExcel.SetCellStyle(hSSFWorkbook, hSSFSheet, num20, num19, leftborder: true, rightborder: true, topborder: true, bottomborder: true, StringAlignment.Center, StringAlignment.Center, font, bkcolor, forcolor, needwrap: false);
- continue;
- }
- DGVtoExcel.SetCellValue(hSSFSheet, num9, num19, nodeText);
- DGVtoExcel.SetCellStyle(hSSFWorkbook, hSSFSheet, num9, num19, leftborder: true, rightborder: true, topborder: true, bottomborder: true, StringAlignment.Center, StringAlignment.Center, font, bkcolor, forcolor, needwrap: false);
- int num21 = num9;
- int num22 = num9 + cellHeightLevels - 1;
- for (int num23 = num21; num23 <= num22; num23++)
- {
- int num24 = num19;
- int num25 = num19 + cellWidthCols - 1;
- for (int num26 = num24; num26 <= num25; num26++)
- {
- if (unchecked(num23 != num9 || num26 != num19))
- {
- DGVtoExcel.SetCellBorder(hSSFWorkbook, hSSFSheet, num23, num26, leftborder: true, rightborder: true, topborder: true, bottomborder: true);
- }
- }
- }
- DGVtoExcel.SetMergeCell(hSSFSheet, num9, num19, num9 + cellHeightLevels - 1, num19 + cellWidthCols - 1);
- }
- }
- mytree.Dispose();
- }
- num9++;
- }
- int num27 = 1;
- int num28 = 0;
- int num29 = 0;
- int num30 = 0;
- int num31 = 0;
- int num32 = 1;
- int num33 = 0;
- int num34 = dataGridView.RowCount - 1;
- for (int num35 = num33; num35 <= num34; num35++)
- {
- IRow row3 = hSSFSheet.CreateRow(num9 + num35);
- row3.HeightInPoints = Module1.ConvertMmToInch(ruler.ConvertToMM(dataGridView.Rows[num35].Height, isX: false)) * 72f;
- if (!dataGridView.Rows[num35].Visible)
- {
- row3.ZeroHeight = true;
- }
- //if (num35 + num9 == 1048575)
- {
- break;
- }
- }
- int num36 = 0;
- int num37 = 0;
- if (isshowprogress)
- {
- progressexcel.ProgressBar1.Maximum = num;
- }
- int num38 = 0;
- int num39 = dataGridView.RowCount - 1;
- for (int num40 = num38; num40 <= num39; num40++)
- {
- bool flag3 = false;
- if (isshowprogress)
- {
- progressexcel.Label1.Text = "正在导出第〖" + Conversions.ToString(num40 + num2 + 1) + "〗条记录,共〖" + Conversions.ToString(num) + "〗条记录,已完成〖" + Strings.Format((double)(num40 + num2 + 1) / (double)num, "###.##%") + "〗";
- progressexcel.ProgressBar1.Value = num40 + 1;
- Application.DoEvents();
- }
- if (Module1.G_CancelExportDGVToExcel)
- {
- break;
- }
- int num41 = 0;
- int num42 = num3 - 1;
- for (num6 = num41; num6 <= num42; num6++)
- {
- int num43;
- if (dataGridView.Columns[array3[num6]].ValueType == null)
- {
- num43 = 0;
- }
- else
- {
- switch (Strings.Left(dataGridView.Columns[array3[num6]].ValueType.Name.ToUpper(), 3))
- {
- case "STR":
- num43 = 0;
- break;
- case "INT":
- case "DEC":
- num43 = 1;
- flag3 = false;
- break;
- case "DAT":
- num43 = 2;
- break;
- case "BOO":
- num43 = 3;
- flag3 = false;
- break;
- default:
- num43 = 0;
- break;
- }
- }
- num32 = 1;
- num27 = 1;
- num30 = 0;
- num28 = 0;
- num31 = 0;
- num30 = 0;
- num28 = 0;
- num29 = 0;
- string text = Conversions.ToString(dataGridView.Rows[num40].Cells[array3[num6]].Tag);
- switch (text)
- {
- default:
- {
- float mywidth = 0f;
- float num44 = 9f;
- int firstcolumn = 0;
- int firstrow = 0;
- int firstc = 0;
- int firstr = 0;
- switch (text)
- {
- default:
- num32 = 1;
- num27 = 1;
- break;
- case "合并":
- case "左上合并":
- case "左下合并":
- case "右上合并":
- case "右下合并":
- case "上边合并":
- case "下边合并":
- case "左边合并":
- case "右边合并":
- mymerge.GetHVMergeWidthAndHeight(dataGridView, array3[num6], num40, ref mywidth, ref num44, ref num31, ref num30, ref num28, ref num29, ref firstcolumn, ref firstrow, ref firstc, ref firstr);
- num32 = num30 + num31 + 1;
- num27 = num28 + num29 + 1;
- break;
- case "水平合并":
- case "#水平合并#":
- case "左合并":
- case "右合并":
- mywidth = (int)Math.Round(mymerge.GetHMergeWidth(dataGridView, array3[num6], num40, ref num32, ref num30, ref num31, ref firstcolumn, ref firstc, iscancheckheight: true));
- break;
- }
- break;
- }
- case "垂直合并":
- case "#垂直合并#":
- case "上合并":
- case "下合并":
- {
- int firstrow = 0;
- int firstr = 0;
- float num44 = mymerge.GetVMergeHeight(dataGridView, array3[num6], num40, ref num27, ref num29, ref num28, ref firstrow, ref firstr);
- break;
- }
- }
- if (unchecked(num30 > 0 || num28 > 0))
- {
- continue;
- }
- if (Operators.CompareString(Versioned.TypeName(dataGridView.Columns[array3[num6]]), "DataGridViewImageColumn", TextCompare: false) == 0)
- {
- if (dataGridView.Rows[num40].Cells[array3[num6]].Value != null)
- {
- Image img = (Image)dataGridView.Rows[num40].Cells[array3[num6]].FormattedValue;
- byte[] byteByImage = DGVtoExcel.GetByteByImage(img);
- int pictureIndex = hSSFWorkbook.AddPicture(byteByImage, PictureType.JPEG);
- IDrawing drawing = hSSFSheet.CreateDrawingPatriarch();
- XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, num6, num9 + num40, num6 + 1, num9 + num40 + 1);
- drawing.CreatePicture(anchor, pictureIndex);
- }
- }
- else if (Operators.CompareString(Versioned.TypeName(dataGridView.Columns[array3[num6]]), "DataGridViewCheckBoxColumn", TextCompare: false) == 0)
- {
- if (dataGridView.Rows[num40].Cells[array3[num6]].Value != null && Conversions.ToBoolean(dataGridView.Rows[num40].Cells[array3[num6]].FormattedValue))
- {
- DGVtoExcel.SetCellValue(hSSFSheet, num9 + num40, num6, "√");
- }
- flag3 = false;
- }
- else
- {
- string text2 = Conversions.ToString(dataGridView.Rows[num40].Cells[array3[num6]].FormattedValue) ?? "";
- flag3 = Strings.InStr(text2, "\r\n") > 0;
- switch (num43)
- {
- case 1:
- if (Versioned.IsNumeric(text2))
- {
- DGVtoExcel.SetCellValue(hSSFSheet, num9 + num40, num6, Conversions.ToDouble(text2));
- }
- else
- {
- DGVtoExcel.SetCellValue(hSSFSheet, num9 + num40, num6, text2);
- }
- break;
- case 2:
- DGVtoExcel.SetCellValue(hSSFSheet, num9 + num40, num6, text2);
- break;
- default:
- DGVtoExcel.SetCellValue(hSSFSheet, num9 + num40, num6, text2);
- break;
- }
- }
- DataGridViewCellStyle dGVCellStyle = Module1.GetDGVCellStyle(dataGridView.Rows[num40].Cells[array3[num6]]);
- DataGridViewContentAlignment alignment = dGVCellStyle.Alignment;
- StringAlignment valign = StringAlignment.Center;
- StringAlignment halign = StringAlignment.Center;
- switch (alignment)
- {
- case DataGridViewContentAlignment.BottomCenter:
- valign = StringAlignment.Far;
- halign = StringAlignment.Center;
- break;
- case DataGridViewContentAlignment.MiddleCenter:
- valign = StringAlignment.Center;
- halign = StringAlignment.Center;
- break;
- case DataGridViewContentAlignment.TopCenter:
- valign = StringAlignment.Near;
- halign = StringAlignment.Center;
- break;
- case DataGridViewContentAlignment.BottomLeft:
- valign = StringAlignment.Far;
- halign = StringAlignment.Near;
- break;
- case DataGridViewContentAlignment.MiddleLeft:
- valign = StringAlignment.Center;
- halign = StringAlignment.Near;
- break;
- case DataGridViewContentAlignment.TopLeft:
- valign = StringAlignment.Near;
- halign = StringAlignment.Near;
- break;
- case DataGridViewContentAlignment.BottomRight:
- valign = StringAlignment.Far;
- halign = StringAlignment.Far;
- break;
- case DataGridViewContentAlignment.MiddleRight:
- valign = StringAlignment.Center;
- halign = StringAlignment.Far;
- break;
- case DataGridViewContentAlignment.TopRight:
- valign = StringAlignment.Near;
- halign = StringAlignment.Far;
- break;
- }
- if (string.Concat(dataGridView.Rows[num40].Cells[array3[num6]].Tag).Contains("合并"))
- {
- valign = StringAlignment.Center;
- halign = StringAlignment.Center;
- }
- if (!flag3 && dGVCellStyle.WrapMode == DataGridViewTriState.True)
- {
- flag3 = true;
- }
- Color dGVCellBackColor = Module1.GetDGVCellBackColor(dataGridView.Rows[num40].Cells[array3[num6]]);
- Color dGVCellForeColor = Module1.GetDGVCellForeColor(dataGridView.Rows[num40].Cells[array3[num6]]);
- DGVtoExcel.SetCellStyle(hSSFWorkbook, hSSFSheet, num9 + num40, num6, leftborder: true, rightborder: true, topborder: true, bottomborder: true, halign, valign, Module1.GetDGVCellFont(dataGridView.Rows[num40].Cells[array3[num6]]), dGVCellBackColor, dGVCellForeColor, flag3);
- if (unchecked(num32 == 1 && num27 == 1))
- {
- continue;
- }
- int num45 = num9 + num40;
- int num46 = num9 + num40 + num29;
- for (int num47 = num45; num47 <= num46; num47++)
- {
- int num48 = num6;
- int num49 = num6 + num31;
- for (int num50 = num48; num50 <= num49; num50++)
- {
- unchecked
- {
- if (num47 != checked(num9 + num40) || num50 != num6)
- {
- DGVtoExcel.SetCellBorder(hSSFWorkbook, hSSFSheet, num47, num50, leftborder: true, rightborder: true, topborder: true, bottomborder: true);
- }
- }
- }
- }
- DGVtoExcel.SetMergeCell(hSSFSheet, num9 + num40, num6, num9 + num40 + num29, num6 + num31);
- num6 += num31;
- }
- if (!((num40 + num9 == 1048575) & (num40 != dataGridView.RowCount - 1)))
- {
- continue;
- }
- int num51 = 0;
- int num52 = num3 - 1;
- for (int num53 = num51; num53 <= num52; num53++)
- {
- hSSFSheet.SetColumnWidth(num53, (int)Math.Round(Math.Ceiling((double)dataGridView.Columns[array3[num53]].Width / 8.0) * 256.0));
- }
- num36++;
- excelNewSheetName = DGVtoExcel.GetExcelNewSheetName(hSSFWorkbook, empty);
- hSSFSheet = (XSSFSheet)hSSFWorkbook.CreateSheet(excelNewSheetName);
- num37 = 1;
- int num54 = num40 + 1;
- int num55 = dataGridView.RowCount - 1;
- for (num6 = num54; num6 <= num55; num6++)
- {
- IRow row4 = hSSFSheet.CreateRow(num37 - 1);
- if (!dataGridView.Rows[num6].Visible)
- {
- row4.ZeroHeight = true;
- }
- row4.HeightInPoints = Module1.ConvertMmToInch(ruler.ConvertToMM(dataGridView.Rows[num6].Height, isX: false)) * 72f;
- if (num37 == 1048576)
- {
- break;
- }
- num37++;
- }
- num9 = -num40 - 1;
- }
- num9 = ((num37 != 0) ? (num37 - 1) : (num9 + dataGridView.RowCount));
- if (Operators.CompareString(TableFooter, "", TextCompare: false) != 0)
- {
- DGVtoExcel.SetTitle(hSSFWorkbook, hSSFSheet, num9, num9, 0, endcol, TableFooter, tablefooterfont);
- }
- DGVtoExcel.w_font = null;
- DGVtoExcel.w_ifont = null;
- DGVtoExcel.w_Cellstyle = null;
- DGVtoExcel.w_iCellstyle = null;
- DGVtoExcel.w_color = null;
- int num56 = 0;
- int num57 = num3 - 1;
- for (int num58 = num56; num58 <= num57; num58++)
- {
- hSSFSheet.SetColumnWidth(num58, (int)Math.Round(Math.Ceiling((double)dataGridView.Columns[array3[num58]].Width / 8.0) * 256.0));
- }
- hSSFWorkbook.SetActiveSheet(hSSFWorkbook.GetSheetIndex(excelNewSheetName));
- }
- num2 += mydgvs[j].Rows.Count;
- }
- ruler.Dispose();
- ruler = null;
- if (isshowprogress)
- {
- progressexcel.Close();
- progressexcel.Dispose();
- }
- if (!DGVtoExcel.WriteToFile(hSSFWorkbook, FileName))
- {
- hSSFWorkbook = null;
- result = false;
- }
- else
- {
- hSSFWorkbook = null;
- if (isopenfile && Interaction.MsgBox("导出的Excel文件已保存到【" + FileName + " 】\r\n您是否要立即打开这个文件以查看其内容?", MsgBoxStyle.YesNoCancel, "提示信息") == MsgBoxResult.Yes)
- {
- try
- {
- Process.Start(FileName);
- }
- catch (Exception projectError3)
- {
- Logger.Error(projectError3, "list-projectError3");
- MessageBox.Show(projectError3.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
- ProjectData.SetProjectError(projectError3);
- try
- {
- Thread.Sleep(100);
- Process.Start(FileName);
- }
- catch (Exception projectError4)
- {
- Logger.Error(projectError4, "list-projectError4");
- MessageBox.Show(projectError4.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
- ProjectData.SetProjectError(projectError4);
- ProjectData.ClearProjectError();
- }
- ProjectData.ClearProjectError();
- }
- }
- result = true;
- }
- }
- catch (Exception projectError5)
- {
- Logger.Error(projectError5, "list-projectError5");
- MessageBox.Show(projectError5.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
- ProjectData.SetProjectError(projectError5);
- if (isshowprogress)
- {
- progressexcel.Close();
- progressexcel.Dispose();
- }
- try
- {
- ruler.Dispose();
- ruler = null;
- }
- catch (Exception projectError6)
- {
- Logger.Error(projectError6, "list-projectError6");
- MessageBox.Show(projectError6.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
- ProjectData.SetProjectError(projectError6);
- ProjectData.ClearProjectError();
- }
- }
- }
- return result;
- }
- }
- /*
- public bool ExportExcelOneSheet(List<DataGridView> mydgvs, List<TreeView> columnheadertrees, Font titlefont, string title, string FileName, Font tableheaderfont, string Tableheader, Font tablefooterfont, string TableFooter, List<string> sheetnames, bool isopenfile, bool isshowprogress, bool isTopNodeFill)
- {
- bool result = true;
- int num = 0;
- checked
- {
- if (mydgvs == null || mydgvs.Count == 0 || sheetnames == null || sheetnames.Count == 0 || mydgvs.Count != sheetnames.Count)
- {
- result = false;
- }
- else
- {
- if (columnheadertrees != null && columnheadertrees.Count > 0 && mydgvs.Count != columnheadertrees.Count)
- {
- return false;
- }
- int num2 = 0;
- if (titlefont == null)
- {
- titlefont = new Font("黑体", 18f, FontStyle.Bold);
- }
- if (tableheaderfont == null)
- {
- tableheaderfont = new Font("宋体", 12f);
- }
- if (tablefooterfont == null)
- {
- tablefooterfont = new Font("宋体", 12f);
- }
- progressexcel progressexcel = null;
- Module1.G_CancelExportDGVToExcel = false;
- if (isshowprogress)
- {
- progressexcel = new progressexcel();
- progressexcel.TopMost = true;
- progressexcel.Visible = true;
- }
- Ruler ruler = new Ruler();
- try
- {
- if (isshowprogress)
- {
- progressexcel.Label1.Text = "正在做导出前的准备,请稍侯……";
- progressexcel.ProgressBar1.Value = 0;
- Application.DoEvents();
- }
- bool flag = false;
- DataGridView dataGridView = null;
- TreeView treeView = null;
- XSSFWorkbook hSSFWorkbook = null;
- XSSFSheet hSSFSheet = null;
- string empty = string.Empty;
- string text = string.Empty;
- for (int i = 0; i < mydgvs.Count; i++)
- {
- empty = sheetnames[i];
- dataGridView = mydgvs[i];
- if (columnheadertrees != null && columnheadertrees.Count > 0)
- {
- treeView = columnheadertrees[i];
- }
- int columnCount = dataGridView.ColumnCount;
- int[] array = new int[columnCount - 1 + 1];
- int[] array2 = new int[columnCount - 1 + 1];
- int num3 = 0;
- int num4 = 0;
- int num5 = columnCount - 1;
- for (int j = num4; j <= num5; j++)
- {
- array[j] = j;
- array2[j] = dataGridView.Columns[j].DisplayIndex;
- if (dataGridView.Columns[j].Visible)
- {
- num3++;
- }
- }
- if (num3 <= 0)
- {
- if (isshowprogress)
- {
- progressexcel.Close();
- progressexcel.Dispose();
- }
- result = true;
- }
- else
- {
- Array.Sort(array2, array);
- int[] array3 = new int[num3 - 1 + 1];
- int num6 = 0;
- int num7 = 0;
- int num8 = columnCount - 1;
- for (int k = num7; k <= num8; k++)
- {
- if (dataGridView.Columns[array[k]].Visible)
- {
- array3[num6] = array[k];
- num6++;
- }
- }
- DGVtoExcel.w_ZDYcolors = 8;
- int endcol = num3 - 1;
- if (!flag)
- {
- SaveFileDialog saveFileDialog = new SaveFileDialog();
- saveFileDialog.Title = "请选择要导出Excel文件的路径和文件名";
- saveFileDialog.AddExtension = true;
- saveFileDialog.OverwritePrompt = false;
- saveFileDialog.DefaultExt = "xls";
- saveFileDialog.Filter = "97-2003 Excel文件(*.xls)|*.xls|所有文件(*.*)|*.*";
- saveFileDialog.FileName = FileName;
- if (isshowprogress)
- {
- progressexcel.Visible = false;
- }
- if (saveFileDialog.ShowDialog() == DialogResult.Cancel)
- {
- if (isshowprogress)
- {
- progressexcel.Close();
- progressexcel.Dispose();
- }
- saveFileDialog.Dispose();
- result = false;
- return result;
- }
- FileName = saveFileDialog.FileName;
- saveFileDialog.Dispose();
- if (isshowprogress)
- {
- progressexcel.Visible = true;
- }
- DGVtoExcel.w_font = null;
- DGVtoExcel.w_ifont = null;
- DGVtoExcel.w_Cellstyle = null;
- DGVtoExcel.w_iCellstyle = null;
- DGVtoExcel.w_color = null;
- if (MyProject.Computer.FileSystem.FileExists(FileName))
- {
- if (isshowprogress)
- {
- progressexcel.Visible = false;
- }
- switch (Interaction.MsgBox("选择的文件【" + FileName + "】已经存在,您确定要覆盖原来的文件吗?注意:覆盖原文件后,原文件中的全部数据都将丢失!\r\n单击[是]按钮,将覆盖原文件,单击[否]按钮,导出数据将以追加的形式添加到文件中,单击[取消]按钮将取消导出", MsgBoxStyle.YesNoCancel | MsgBoxStyle.Question, "提示信息"))
- {
- case MsgBoxResult.Cancel:
- if (isshowprogress)
- {
- progressexcel.Close();
- progressexcel.Dispose();
- }
- result = false;
- return result;
- case MsgBoxResult.Yes:
- try
- {
- MyProject.Computer.FileSystem.DeleteFile(FileName, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- Interaction.MsgBox("数据导出失败,原因是文件【" + FileName + "】无法覆盖,可能该文件正在使用中,请关闭该文件后再试", MsgBoxStyle.Exclamation, "提示信息");
- if (isshowprogress)
- {
- progressexcel.Close();
- progressexcel.Dispose();
- }
- result = false;
- ProjectData.ClearProjectError();
- return result;
- }
- break;
- }
- if (isshowprogress)
- {
- progressexcel.Visible = true;
- }
- }
- if (MyProject.Computer.FileSystem.FileExists(FileName))
- {
- FileStream fileStream;
- try
- {
- fileStream = new FileStream(FileName, FileMode.Open, FileAccess.Read);
- }
- catch (Exception ex)
- {
- ProjectData.SetProjectError(ex);
- Exception ex2 = ex;
- if (isshowprogress)
- {
- progressexcel.Close();
- progressexcel.Dispose();
- }
- Interaction.MsgBox("数据导出失败,原因是打开Excel文件〖" + FileName + "〗失败," + ex2.Message, MsgBoxStyle.Exclamation, "提示信息");
- fileStream = null;
- result = false;
- ProjectData.ClearProjectError();
- return result;
- }
- try
- {
- hSSFWorkbook = new XSSFWorkbook(fileStream);
- }
- catch (Exception projectError2)
- {
- ProjectData.SetProjectError(projectError2);
- if (isshowprogress)
- {
- progressexcel.Close();
- progressexcel.Dispose();
- }
- fileStream.Dispose();
- fileStream = null;
- Interaction.MsgBox("数据导出失败,原因是打开Excel文件〖" + FileName + "〗失败,可能不是有效的Office97-2003 Excel文件格式,因此无法向该文件中追加导出的数据", MsgBoxStyle.Exclamation, "提示信息");
- hSSFWorkbook = null;
- result = false;
- ProjectData.ClearProjectError();
- return result;
- }
- }
- else
- {
- hSSFWorkbook = new XSSFWorkbook();
- }
- flag = true;
- }
- if (hSSFSheet == null)
- {
- text = DGVtoExcel.GetExcelNewSheetName(hSSFWorkbook, title);
- hSSFSheet = (XSSFSheet)hSSFWorkbook.CreateSheet(text);
- }
- int num9;
- if (Operators.CompareString(title, "", TextCompare: false) == 0)
- {
- num9 = 0;
- }
- else
- {
- DGVtoExcel.SetTitle(hSSFWorkbook, hSSFSheet, num2, num2, 0, endcol, empty, titlefont);
- num9 = 1;
- }
- if (Operators.CompareString(Tableheader, "", TextCompare: false) != 0)
- {
- DGVtoExcel.SetTitle(hSSFWorkbook, hSSFSheet, num9 + num2, num9 + num2, 0, endcol, Tableheader, tableheaderfont);
- num9++;
- }
- num9 += num2;
- DGVtoExcel.w_gridcolor = DGVtoExcel.GetXLColour(hSSFWorkbook, dataGridView.GridColor);
- if (dataGridView.ColumnHeadersVisible)
- {
- if (treeView == null)
- {
- IRow row = hSSFSheet.CreateRow(num9);
- row.HeightInPoints = Module1.ConvertMmToInch(ruler.ConvertToMM(dataGridView.ColumnHeadersHeight, isX: false)) * 72f;
- int num10 = 0;
- int num11 = num3 - 1;
- for (int l = num10; l <= num11; l++)
- {
- DGVtoExcel.SetCellValue(hSSFSheet, num9, l, dataGridView.Columns[array3[l]].HeaderText);
- Font dGVHeaderFont = Module1.GetDGVHeaderFont(dataGridView.Columns[array3[l]]);
- Color dGVHeaderBackColor = Module1.GetDGVHeaderBackColor(dataGridView.Columns[array3[l]]);
- Color dGVHeaderForeColor = Module1.GetDGVHeaderForeColor(dataGridView.Columns[array3[l]]);
- DGVtoExcel.SetCellStyle(hSSFWorkbook, hSSFSheet, num9, l, leftborder: true, rightborder: true, topborder: true, bottomborder: true, StringAlignment.Center, StringAlignment.Center, dGVHeaderFont, dGVHeaderBackColor, dGVHeaderForeColor, needwrap: false);
- }
- }
- else
- {
- mytree mytree = new mytree(treeView, dataGridView);
- num = mytree.GetLeves();
- int num12 = 1;
- int num13 = num;
- for (int m = num12; m <= num13; m++)
- {
- IRow row2 = hSSFSheet.CreateRow(num9 + m - 1);
- row2.HeightInPoints = Module1.ConvertMmToInch(ruler.ConvertToMM((float)((double)dataGridView.ColumnHeadersHeight / (double)num), isX: false)) * 72f;
- }
- int num14 = 1;
- int num15 = num;
- for (int n = num14; n <= num15; n++)
- {
- if (n != 1)
- {
- num9++;
- }
- int num16 = 0;
- int num17 = num3 - 1;
- bool flag2 = true;
- for (int num18 = num16; num18 <= num17; num18++)
- {
- string nodeText = mytree.GetNodeText(array3[num18], n);
- int cellHeightLevels = mytree.GetCellHeightLevels(array3[num18], n, isTopNodeFill, out flag2);
- int cellWidthCols = mytree.GetCellWidthCols(array3[num18], n);
- if (unchecked(cellHeightLevels == 0 || cellWidthCols == 0))
- {
- continue;
- }
- Font font = mytree.GetNodeFont(array3[num18], n);
- if (font == null)
- {
- font = Module1.GetDGVHeaderFont(dataGridView.Columns[array3[num18]]);
- }
- Color forcolor = mytree.GetNodeForeColor(array3[num18], n);
- if (forcolor.IsEmpty)
- {
- forcolor = Module1.GetDGVHeaderForeColor(dataGridView.Columns[array3[num18]]);
- }
- Color bkcolor = mytree.GetNodeBackColor(array3[num18], n);
- if (bkcolor.IsEmpty)
- {
- bkcolor = Module1.GetDGVHeaderBackColor(dataGridView.Columns[array3[num18]]);
- }
- if (unchecked(cellWidthCols == 1 && cellHeightLevels == 1))
- {
- int num19 = num9;
- if (!flag2)
- {
- num19++;
- }
- DGVtoExcel.SetCellValue(hSSFSheet, num19, num18, nodeText);
- DGVtoExcel.SetCellStyle(hSSFWorkbook, hSSFSheet, num19, num18, leftborder: true, rightborder: true, topborder: true, bottomborder: true, StringAlignment.Center, StringAlignment.Center, font, bkcolor, forcolor, needwrap: false);
- continue;
- }
- DGVtoExcel.SetCellValue(hSSFSheet, num9, num18, nodeText);
- DGVtoExcel.SetCellStyle(hSSFWorkbook, hSSFSheet, num9, num18, leftborder: true, rightborder: true, topborder: true, bottomborder: true, StringAlignment.Center, StringAlignment.Center, font, bkcolor, forcolor, needwrap: false);
- int num20 = num9;
- int num21 = num9 + cellHeightLevels - 1;
- for (int num22 = num20; num22 <= num21; num22++)
- {
- int num23 = num18;
- int num24 = num18 + cellWidthCols - 1;
- for (int num25 = num23; num25 <= num24; num25++)
- {
- if (unchecked(num22 != num9 || num25 != num18))
- {
- DGVtoExcel.SetCellBorder(hSSFWorkbook, hSSFSheet, num22, num25, leftborder: true, rightborder: true, topborder: true, bottomborder: true);
- }
- }
- }
- DGVtoExcel.SetMergeCell(hSSFSheet, num9, num18, num9 + cellHeightLevels - 1, num18 + cellWidthCols - 1);
- }
- }
- mytree.Dispose();
- }
- num9++;
- }
- int num26 = 1;
- int num27 = 0;
- int num28 = 0;
- int num29 = 0;
- int num30 = 0;
- int num31 = 1;
- int num32 = 0;
- int num33 = dataGridView.RowCount - 1;
- for (int num34 = num32; num34 <= num33; num34++)
- {
- IRow row3 = hSSFSheet.CreateRow(num9 + num34);
- row3.HeightInPoints = Module1.ConvertMmToInch(ruler.ConvertToMM(dataGridView.Rows[num34].Height, isX: false)) * 72f;
- if (!dataGridView.Rows[num34].Visible)
- {
- row3.ZeroHeight = true;
- }
- if (num34 + num9 == 1048575)
- {
- break;
- }
- }
- int num35 = 0;
- int num36 = 0;
- if (isshowprogress)
- {
- progressexcel.ProgressBar1.Maximum = dataGridView.RowCount;
- }
- int num37 = 0;
- int num38 = dataGridView.RowCount - 1;
- for (int num39 = num37; num39 <= num38; num39++)
- {
- bool flag3 = false;
- if (isshowprogress)
- {
- progressexcel.Label1.Text = "正在导出第〖" + Conversions.ToString(num39 + 1) + "〗条记录,共〖" + Conversions.ToString(dataGridView.RowCount) + "〗条记录,已完成〖" + Strings.Format((double)(num39 + 1) / (double)dataGridView.RowCount, "###.##%") + "〗";
- progressexcel.ProgressBar1.Value = num39 + 1;
- Application.DoEvents();
- }
- if (Module1.G_CancelExportDGVToExcel)
- {
- break;
- }
- int num40 = 0;
- int num41 = num3 - 1;
- for (num6 = num40; num6 <= num41; num6++)
- {
- int num42;
- if (dataGridView.Columns[array3[num6]].ValueType == null)
- {
- num42 = 0;
- }
- else
- {
- switch (Strings.Left(dataGridView.Columns[array3[num6]].ValueType.Name.ToUpper(), 3))
- {
- case "STR":
- num42 = 0;
- break;
- case "INT":
- case "DEC":
- num42 = 1;
- flag3 = false;
- break;
- case "DAT":
- num42 = 2;
- break;
- case "BOO":
- num42 = 3;
- flag3 = false;
- break;
- default:
- num42 = 0;
- break;
- }
- }
- num31 = 1;
- num26 = 1;
- num29 = 0;
- num27 = 0;
- num30 = 0;
- num29 = 0;
- num27 = 0;
- num28 = 0;
- string text2 = Conversions.ToString(dataGridView.Rows[num39].Cells[array3[num6]].Tag);
- switch (text2)
- {
- default:
- {
- float mywidth = 0f;
- float num43 = 9f;
- int firstcolumn = 0;
- int firstrow = 0;
- int firstc = 0;
- int firstr = 0;
- switch (text2)
- {
- default:
- num31 = 1;
- num26 = 1;
- break;
- case "合并":
- case "左上合并":
- case "左下合并":
- case "右上合并":
- case "右下合并":
- case "上边合并":
- case "下边合并":
- case "左边合并":
- case "右边合并":
- mymerge.GetHVMergeWidthAndHeight(dataGridView, array3[num6], num39, ref mywidth, ref num43, ref num30, ref num29, ref num27, ref num28, ref firstcolumn, ref firstrow, ref firstc, ref firstr);
- num31 = num29 + num30 + 1;
- num26 = num27 + num28 + 1;
- break;
- case "水平合并":
- case "#水平合并#":
- case "左合并":
- case "右合并":
- mywidth = (int)Math.Round(mymerge.GetHMergeWidth(dataGridView, array3[num6], num39, ref num31, ref num29, ref num30, ref firstcolumn, ref firstc, iscancheckheight: true));
- break;
- }
- break;
- }
- case "垂直合并":
- case "#垂直合并#":
- case "上合并":
- case "下合并":
- {
- int firstrow = 0;
- int firstr = 0;
- float num43 = mymerge.GetVMergeHeight(dataGridView, array3[num6], num39, ref num26, ref num28, ref num27, ref firstrow, ref firstr);
- break;
- }
- }
- if (unchecked(num29 > 0 || num27 > 0))
- {
- continue;
- }
- if (Operators.CompareString(Versioned.TypeName(dataGridView.Columns[array3[num6]]), "DataGridViewImageColumn", TextCompare: false) == 0)
- {
- if (dataGridView.Rows[num39].Cells[array3[num6]].Value != null)
- {
- Image img = (Image)dataGridView.Rows[num39].Cells[array3[num6]].FormattedValue;
- byte[] byteByImage = DGVtoExcel.GetByteByImage(img);
- int pictureIndex = hSSFWorkbook.AddPicture(byteByImage, PictureType.JPEG);
- IDrawing drawing = hSSFSheet.CreateDrawingPatriarch();
- XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, num6, num9 + num39, num6 + 1, num9 + num39 + 1);
- drawing.CreatePicture(anchor, pictureIndex);
- }
- }
- else if (Operators.CompareString(Versioned.TypeName(dataGridView.Columns[array3[num6]]), "DataGridViewCheckBoxColumn", TextCompare: false) == 0)
- {
- if (dataGridView.Rows[num39].Cells[array3[num6]].Value != null && Conversions.ToBoolean(dataGridView.Rows[num39].Cells[array3[num6]].FormattedValue))
- {
- DGVtoExcel.SetCellValue(hSSFSheet, num9 + num39, num6, "√");
- }
- flag3 = false;
- }
- else
- {
- string text3 = Conversions.ToString(dataGridView.Rows[num39].Cells[array3[num6]].FormattedValue) ?? "";
- flag3 = Strings.InStr(text3, "\r\n") > 0;
- switch (num42)
- {
- case 1:
- if (Versioned.IsNumeric(text3))
- {
- DGVtoExcel.SetCellValue(hSSFSheet, num9 + num39, num6, Conversions.ToDouble(text3));
- }
- else
- {
- DGVtoExcel.SetCellValue(hSSFSheet, num9 + num39, num6, text3);
- }
- break;
- case 2:
- DGVtoExcel.SetCellValue(hSSFSheet, num9 + num39, num6, text3);
- break;
- default:
- DGVtoExcel.SetCellValue(hSSFSheet, num9 + num39, num6, text3);
- break;
- }
- }
- DataGridViewCellStyle dGVCellStyle = Module1.GetDGVCellStyle(dataGridView.Rows[num39].Cells[array3[num6]]);
- DataGridViewContentAlignment alignment = dGVCellStyle.Alignment;
- StringAlignment valign = StringAlignment.Center;
- StringAlignment halign = StringAlignment.Center;
- switch (alignment)
- {
- case DataGridViewContentAlignment.BottomCenter:
- valign = StringAlignment.Far;
- halign = StringAlignment.Center;
- break;
- case DataGridViewContentAlignment.MiddleCenter:
- valign = StringAlignment.Center;
- halign = StringAlignment.Center;
- break;
- case DataGridViewContentAlignment.TopCenter:
- valign = StringAlignment.Near;
- halign = StringAlignment.Center;
- break;
- case DataGridViewContentAlignment.BottomLeft:
- valign = StringAlignment.Far;
- halign = StringAlignment.Near;
- break;
- case DataGridViewContentAlignment.MiddleLeft:
- valign = StringAlignment.Center;
- halign = StringAlignment.Near;
- break;
- case DataGridViewContentAlignment.TopLeft:
- valign = StringAlignment.Near;
- halign = StringAlignment.Near;
- break;
- case DataGridViewContentAlignment.BottomRight:
- valign = StringAlignment.Far;
- halign = StringAlignment.Far;
- break;
- case DataGridViewContentAlignment.MiddleRight:
- valign = StringAlignment.Center;
- halign = StringAlignment.Far;
- break;
- case DataGridViewContentAlignment.TopRight:
- valign = StringAlignment.Near;
- halign = StringAlignment.Far;
- break;
- }
- if (string.Concat(dataGridView.Rows[num39].Cells[array3[num6]].Tag).Contains("合并"))
- {
- valign = StringAlignment.Center;
- halign = StringAlignment.Center;
- }
- if (!flag3 && dGVCellStyle.WrapMode == DataGridViewTriState.True)
- {
- flag3 = true;
- }
- Color dGVCellBackColor = Module1.GetDGVCellBackColor(dataGridView.Rows[num39].Cells[array3[num6]]);
- Color dGVCellForeColor = Module1.GetDGVCellForeColor(dataGridView.Rows[num39].Cells[array3[num6]]);
- DGVtoExcel.SetCellStyle(hSSFWorkbook, hSSFSheet, num9 + num39, num6, leftborder: true, rightborder: true, topborder: true, bottomborder: true, halign, valign, Module1.GetDGVCellFont(dataGridView.Rows[num39].Cells[array3[num6]]), dGVCellBackColor, dGVCellForeColor, flag3);
- if (unchecked(num31 == 1 && num26 == 1))
- {
- continue;
- }
- int num44 = num9 + num39;
- int num45 = num9 + num39 + num28;
- for (int num46 = num44; num46 <= num45; num46++)
- {
- int num47 = num6;
- int num48 = num6 + num30;
- for (int num49 = num47; num49 <= num48; num49++)
- {
- unchecked
- {
- if (num46 != checked(num9 + num39) || num49 != num6)
- {
- DGVtoExcel.SetCellBorder(hSSFWorkbook, hSSFSheet, num46, num49, leftborder: true, rightborder: true, topborder: true, bottomborder: true);
- }
- }
- }
- }
- DGVtoExcel.SetMergeCell(hSSFSheet, num9 + num39, num6, num9 + num39 + num28, num6 + num30);
- num6 += num30;
- }
- if (!((num39 + num9 == 1048575) & (num39 != dataGridView.RowCount - 1)))
- {
- continue;
- }
- int num50 = 0;
- int num51 = num3 - 1;
- for (int num52 = num50; num52 <= num51; num52++)
- {
- hSSFSheet.SetColumnWidth(num52, (int)Math.Round(Math.Ceiling((double)dataGridView.Columns[array3[num52]].Width / 8.0) * 256.0));
- }
- num35++;
- text = DGVtoExcel.GetExcelNewSheetName(hSSFWorkbook, empty);
- hSSFSheet = (XSSFSheet)hSSFWorkbook.CreateSheet(text);
- num36 = 1;
- int num53 = num39 + 1;
- int num54 = dataGridView.RowCount - 1;
- for (num6 = num53; num6 <= num54; num6++)
- {
- IRow row4 = hSSFSheet.CreateRow(num36 - 1);
- if (!dataGridView.Rows[num6].Visible)
- {
- row4.ZeroHeight = true;
- }
- row4.HeightInPoints = Module1.ConvertMmToInch(ruler.ConvertToMM(dataGridView.Rows[num6].Height, isX: false)) * 72f;
- if (num36 == 1048576)
- {
- break;
- }
- num36++;
- }
- num9 = -num39 - 1;
- }
- num9 = ((num36 != 0) ? (num36 - 1) : (num9 + dataGridView.RowCount));
- if (Operators.CompareString(TableFooter, "", TextCompare: false) != 0)
- {
- DGVtoExcel.SetTitle(hSSFWorkbook, hSSFSheet, num9, num9, 0, endcol, TableFooter, tablefooterfont);
- }
- DGVtoExcel.w_font = null;
- DGVtoExcel.w_ifont = null;
- DGVtoExcel.w_Cellstyle = null;
- DGVtoExcel.w_iCellstyle = null;
- DGVtoExcel.w_color = null;
- int num55 = 0;
- int num56 = num3 - 1;
- for (int num57 = num55; num57 <= num56; num57++)
- {
- hSSFSheet.SetColumnWidth(num57, (int)Math.Round(Math.Ceiling((double)dataGridView.Columns[array3[num57]].Width / 8.0) * 256.0));
- }
- hSSFWorkbook.SetActiveSheet(hSSFWorkbook.GetSheetIndex(text));
- }
- num2 += mydgvs[i].Rows.Count + ((num == 0) ? 1 : num) + 4;
- }
- ruler.Dispose();
- ruler = null;
- if (isshowprogress)
- {
- progressexcel.Close();
- progressexcel.Dispose();
- }
- if (!DGVtoExcel.WriteToFile(hSSFWorkbook, FileName))
- {
- hSSFWorkbook = null;
- result = false;
- }
- else
- {
- hSSFWorkbook = null;
- if (isopenfile && Interaction.MsgBox("导出的Excel文件已保存到【" + FileName + " 】\r\n您是否要立即打开这个文件以查看其内容?", MsgBoxStyle.YesNoCancel, "提示信息") == MsgBoxResult.Yes)
- {
- try
- {
- Process.Start(FileName);
- }
- catch (Exception projectError3)
- {
- ProjectData.SetProjectError(projectError3);
- try
- {
- Thread.Sleep(100);
- Process.Start(FileName);
- }
- catch (Exception projectError4)
- {
- ProjectData.SetProjectError(projectError4);
- ProjectData.ClearProjectError();
- }
- ProjectData.ClearProjectError();
- }
- }
- result = true;
- }
- }
- catch (Exception projectError5)
- {
- ProjectData.SetProjectError(projectError5);
- if (isshowprogress)
- {
- progressexcel.Close();
- progressexcel.Dispose();
- }
- try
- {
- ruler.Dispose();
- ruler = null;
- }
- catch (Exception projectError6)
- {
- ProjectData.SetProjectError(projectError6);
- ProjectData.ClearProjectError();
- }
- }
- }
- return result;
- }
- }
- public void ExportDGVToPDF(DataGridView dgv, TreeView tv, string title, Font titlefont, Font tableheaderfont, string tableheader, Font tablefooterfont, string tablefooter, string filename, bool isshowprogress)
- {
- //IL_012f: Unknown result type (might be due to invalid IL or missing references)
- //IL_0139: Expected O, but got Unknown
- //IL_021a: Unknown result type (might be due to invalid IL or missing references)
- //IL_0221: Expected O, but got Unknown
- //IL_03c9: Unknown result type (might be due to invalid IL or missing references)
- //IL_03d0: Expected O, but got Unknown
- //IL_0300: Unknown result type (might be due to invalid IL or missing references)
- //IL_0307: Expected O, but got Unknown
- //IL_04ed: Unknown result type (might be due to invalid IL or missing references)
- //IL_04f4: Expected O, but got Unknown
- //IL_05a8: Unknown result type (might be due to invalid IL or missing references)
- //IL_05af: Expected O, but got Unknown
- //IL_0550: Unknown result type (might be due to invalid IL or missing references)
- //IL_0557: Expected O, but got Unknown
- //IL_0702: Unknown result type (might be due to invalid IL or missing references)
- //IL_0709: Expected O, but got Unknown
- _paperwidth = 210f;
- _paperheight = 297f;
- _paperlandscape = false;
- _margin = new Margins(10, 10, 10, 10);
- _repeatheader = true;
- if (dgv == null || dgv.ColumnCount <= 0)
- {
- return;
- }
- progressexcel progressexcel = null;
- SaveFileDialog saveFileDialog = new SaveFileDialog();
- saveFileDialog.Title = "请选择要导出PDF文件的路径和文件名";
- saveFileDialog.AddExtension = true;
- saveFileDialog.OverwritePrompt = false;
- saveFileDialog.DefaultExt = "PDF";
- saveFileDialog.Filter = "PDF文件(*.pdf)|*.pdf";
- saveFileDialog.FileName = filename;
- if (isshowprogress)
- {
- progressexcel = new progressexcel();
- progressexcel.Text = "导出PDF文件";
- progressexcel.TopMost = true;
- progressexcel.Visible = true;
- Module1.G_CancelExportDGVToExcel = false;
- progressexcel.Label1.Text = "正在做导出前的准备,请稍侯……";
- Application.DoEvents();
- }
- if (saveFileDialog.ShowDialog() == DialogResult.Cancel)
- {
- if (isshowprogress)
- {
- progressexcel.Close();
- progressexcel.Dispose();
- }
- saveFileDialog.Dispose();
- return;
- }
- filename = saveFileDialog.FileName;
- saveFileDialog.Dispose();
- if (mydoc != null)
- {
- mydoc.Dispose();
- mydoc = null;
- }
- if (mywriter != null)
- {
- ((DocWriter)mywriter).Dispose();
- mywriter = null;
- }
- FontFactory.RegisterDirectories();
- mydoc = new Document();
- float totalwidth = 0f;
- int[] dGVColWidth = GetDGVColWidth(dgv, ref totalwidth);
- checked
- {
- float[] array = new float[dGVColWidth.Length - 1 + 1];
- int num = 0;
- int num2 = dGVColWidth.Length - 1;
- for (int i = num; i <= num2; i++)
- {
- array[i] = Module1.G_ruler.ConvertToPoint(dGVColWidth[i], isx: true);
- }
- mywriter = PdfWriter.GetInstance(mydoc, (Stream)new FileStream(filename, FileMode.Create));
- mywriter.PageEvent = (IPdfPageEvent)(object)new testevent();
- mydoc.Open();
- if (PaperWidth == 0f)
- {
- totalwidth = Module1.G_ruler.ConvertToMM(totalwidth, isX: true) + (float)PaperMargin.Left + (float)PaperMargin.Right;
- totalwidth = Module1.G_ruler.ConvertToPointFromMM(totalwidth);
- Rectangle pageSize = new Rectangle(0f, 0f, totalwidth, Module1.G_ruler.ConvertToPointFromMM(PaperHeight));
- mydoc.SetPageSize(pageSize);
- mydoc.SetMargins(Module1.G_ruler.ConvertToPointFromMM(_margin.Left), Module1.G_ruler.ConvertToPointFromMM(_margin.Right), Module1.G_ruler.ConvertToPointFromMM(_margin.Top), Module1.G_ruler.ConvertToPointFromMM(_margin.Bottom));
- myratio = 1f;
- }
- else
- {
- totalwidth = Module1.G_ruler.ConvertToMM(totalwidth, isX: true);
- totalwidth = Module1.G_ruler.ConvertToPointFromMM(totalwidth);
- float num3 = Module1.G_ruler.ConvertToPointFromMM(PaperWidth);
- float num4 = Module1.G_ruler.ConvertToPointFromMM(PaperHeight);
- if (unchecked(PaperLandScape || num3 > num4))
- {
- Rectangle val = new Rectangle(0f, 0f, num3, num4);
- mydoc.SetMargins(Module1.G_ruler.ConvertToPointFromMM(_margin.Left), Module1.G_ruler.ConvertToPointFromMM(_margin.Right), Module1.G_ruler.ConvertToPointFromMM(_margin.Top), Module1.G_ruler.ConvertToPointFromMM(_margin.Bottom));
- mydoc.SetPageSize(val.Rotate());
- myratio = (num4 - Module1.G_ruler.ConvertToPointFromMM(_margin.Left) - Module1.G_ruler.ConvertToPointFromMM(_margin.Right)) / totalwidth;
- }
- else
- {
- Rectangle pageSize2 = new Rectangle(0f, 0f, num3, num4);
- mydoc.SetMargins(Module1.G_ruler.ConvertToPointFromMM(_margin.Left), Module1.G_ruler.ConvertToPointFromMM(_margin.Right), Module1.G_ruler.ConvertToPointFromMM(_margin.Top), Module1.G_ruler.ConvertToPointFromMM(_margin.Bottom));
- mydoc.SetPageSize(pageSize2);
- myratio = (num3 - Module1.G_ruler.ConvertToPointFromMM(_margin.Left) - Module1.G_ruler.ConvertToPointFromMM(_margin.Right)) / totalwidth;
- }
- }
- int num5 = 0;
- int num6 = dGVColWidth.Length - 1;
- for (int j = num5; j <= num6; j++)
- {
- array[j] *= myratio;
- }
- mydoc.NewPage();
- if (titlefont == null)
- {
- titlefont = new Font("黑体", 18f, FontStyle.Bold);
- }
- if (title != null && Operators.CompareString(title, "", TextCompare: false) != 0)
- {
- Paragraph val2 = new Paragraph(title, GetPDFFont(titlefont));
- val2.Alignment = 1;
- val2.SpacingAfter = 5f;
- val2.SpacingBefore = 0f;
- mydoc.Add((IElement)(object)val2);
- }
- if (Operators.CompareString(tableheader, "", TextCompare: false) != 0)
- {
- if (tableheaderfont == null)
- {
- tableheaderfont = new Font("宋体", 12f);
- }
- Paragraph val3 = new Paragraph(tableheader, GetPDFFont(tableheaderfont));
- val3.SpacingAfter = 5f;
- mydoc.Add((IElement)(object)val3);
- }
- Module1.G_CancelExportDGVToExcel = false;
- if (isshowprogress)
- {
- progressexcel.ProgressBar1.Maximum = dgv.RowCount;
- progressexcel.Label1.Text = "正导出表头,请稍侯……";
- Application.DoEvents();
- }
- PdfPTable val4 = new PdfPTable(GetDGVVisibleCols(dgv));
- val4.SetWidths(array);
- if (dgv.ColumnHeadersVisible)
- {
- AddHead(dgv, tv, val4);
- }
- int num7 = 0;
- int num8 = dgv.RowCount - 1;
- for (int k = num7; k <= num8; k++)
- {
- if (isshowprogress)
- {
- progressexcel.Label1.Text = "正在导出第〖" + Conversions.ToString(k + 1) + "〗条记录,共〖" + Conversions.ToString(dgv.RowCount) + "〗条记录,已完成〖" + Strings.Format((double)(k + 1) / (double)dgv.RowCount, "###.##%") + "〗";
- progressexcel.ProgressBar1.Value = k + 1;
- Application.DoEvents();
- if (Module1.G_CancelExportDGVToExcel)
- {
- break;
- }
- }
- if (dgv.Rows[k].Visible)
- {
- AddRow(dgv, k, val4);
- }
- }
- if (isshowprogress)
- {
- progressexcel.Close();
- progressexcel.Dispose();
- }
- val4.WidthPercentage = 100f;
- mydoc.Add((IElement)(object)val4);
- if (Operators.CompareString(tablefooter, "", TextCompare: false) != 0)
- {
- if (tablefooterfont == null)
- {
- tablefooterfont = new Font("宋体", 12f);
- }
- Paragraph val5 = new Paragraph(tablefooter, GetPDFFont(tablefooterfont));
- val5.SpacingAfter = 5f;
- mydoc.Add((IElement)(object)val5);
- }
- mydoc.Close();
- ((DocWriter)mywriter).Dispose();
- mywriter = null;
- mydoc.Dispose();
- mydoc = null;
- }
- }
- private int[] GetDGVColWidth(DataGridView dgv, ref float totalwidth)
- {
- totalwidth = 0f;
- if (dgv == null)
- {
- return null;
- }
- int columnCount = dgv.ColumnCount;
- checked
- {
- int[] array = new int[columnCount - 1 + 1];
- int[] array2 = new int[columnCount - 1 + 1];
- int num = 0;
- int num2 = columnCount - 1;
- for (int i = num; i <= num2; i++)
- {
- array[i] = i;
- array2[i] = dgv.Columns[i].DisplayIndex;
- }
- Array.Sort(array2, array);
- int dGVVisibleCols = GetDGVVisibleCols(dgv);
- if (dGVVisibleCols == 0)
- {
- return null;
- }
- int num3 = 0;
- int[] array3 = new int[dGVVisibleCols - 1 + 1];
- int num4 = 0;
- int num5 = columnCount - 1;
- for (int j = num4; j <= num5; j++)
- {
- if (dgv.Columns[array[j]].Visible)
- {
- array3[num3] = dgv.Columns[array[j]].Width;
- totalwidth += array3[num3];
- num3++;
- }
- }
- return array3;
- }
- }
- private int GetDGVVisibleCols(DataGridView dgv)
- {
- if (dgv == null)
- {
- return 0;
- }
- int num = 0;
- int num2 = 0;
- checked
- {
- int num3 = dgv.ColumnCount - 1;
- for (int i = num2; i <= num3; i++)
- {
- if (dgv.Columns[i].Visible)
- {
- num++;
- }
- }
- return num;
- }
- }
- private Font GetPDFFont(Font f)
- {
- if (f == null)
- {
- return null;
- }
- float size = f.Size;
- int num = 0;
- if (f.Bold)
- {
- num |= 1;
- }
- if (f.Italic)
- {
- num |= 2;
- }
- if (f.Underline)
- {
- num |= 4;
- }
- if (f.Strikeout)
- {
- num |= 8;
- }
- return GetPDFFont(f.Name, size, num);
- }
- private Font GetPDFFont(Font f, Color cc)
- {
- if (f == null)
- {
- return null;
- }
- float size = f.Size;
- int num = 0;
- if (f.Bold)
- {
- num |= 1;
- }
- if (f.Italic)
- {
- num |= 2;
- }
- if (f.Underline)
- {
- num |= 4;
- }
- if (f.Strikeout)
- {
- num |= 8;
- }
- return GetPDFFont(f.Name, size, num, GetPDFColor(cc));
- }
- private Font GetPDFFont(string fontname, float size, int style)
- {
- return FontFactory.GetFont(fontname, "Identity-H", false, size, style);
- }
- private Font GetPDFFont(string fontname, float size, int style, BaseColor cc)
- {
- return FontFactory.GetFont(fontname, "Identity-H", false, size, style, cc);
- }
- private void AddHead(DataGridView dgv, PdfPTable tb)
- {
- //IL_010e: Unknown result type (might be due to invalid IL or missing references)
- //IL_0115: Expected O, but got Unknown
- //IL_0117: Unknown result type (might be due to invalid IL or missing references)
- //IL_011e: Expected O, but got Unknown
- if (dgv == null || dgv.ColumnCount <= 0)
- {
- return;
- }
- int columnCount = dgv.ColumnCount;
- checked
- {
- int[] array = new int[columnCount - 1 + 1];
- int[] array2 = new int[columnCount - 1 + 1];
- int num = 0;
- int num2 = columnCount - 1;
- for (int i = num; i <= num2; i++)
- {
- array[i] = i;
- array2[i] = dgv.Columns[i].DisplayIndex;
- }
- Array.Sort(array2, array);
- int num3 = 0;
- int num4 = dgv.ColumnCount - 1;
- for (int j = num3; j <= num4; j++)
- {
- if (dgv.Columns[array[j]].Visible)
- {
- _ = dgv.Columns[array[j]].Width;
- Font dGVHeaderFont = Module1.GetDGVHeaderFont(dgv.Columns[array[j]]);
- Color dGVHeaderForeColor = Module1.GetDGVHeaderForeColor(dgv.Columns[array[j]]);
- Color dGVHeaderBackColor = Module1.GetDGVHeaderBackColor(dgv.Columns[array[j]]);
- Phrase val = new Phrase(dgv.Columns[array[j]].HeaderText, GetPDFFont(dGVHeaderFont, dGVHeaderForeColor));
- PdfPCell val2 = new PdfPCell(val);
- val2.Padding = 1f;
- ((Rectangle)val2).BorderColor = GetPDFColor(dgv.GridColor);
- val2.HorizontalAlignment = 1;
- val2.VerticalAlignment = 5;
- ((Rectangle)val2).BackgroundColor = GetPDFColor(dGVHeaderBackColor);
- if (myratio >= 1f)
- {
- val2.FixedHeight = Module1.G_ruler.ConvertToPoint(dgv.ColumnHeadersHeight, isx: false);
- }
- else
- {
- val2.MinimumHeight = Module1.G_ruler.ConvertToPoint(dgv.ColumnHeadersHeight, isx: false);
- }
- tb.AddCell(val2);
- }
- }
- }
- }
- private void AddHead(DataGridView dgv, TreeView tv, PdfPTable tb)
- {
- if (dgv == null)
- {
- return;
- }
- if (tv == null)
- {
- if (RepeatHeader)
- {
- tb.HeaderRows = 1;
- }
- AddHead(dgv, tb);
- return;
- }
- checked
- {
- float[] array = new float[dgv.ColumnCount - 1 + 1];
- int num = 0;
- int num2 = dgv.ColumnCount - 1;
- for (int i = num; i <= num2; i++)
- {
- array[i] = dgv.Columns[i].Width;
- }
- mytree mytree = new mytree(tv, dgv, array);
- int leves = mytree.GetLeves();
- if (mytree.GetColumns() != dgv.ColumnCount)
- {
- if (RepeatHeader)
- {
- tb.HeaderRows = 1;
- }
- AddHead(dgv, tb);
- }
- else
- {
- if (RepeatHeader)
- {
- tb.HeaderRows = leves;
- }
- int num3 = 1;
- int num4 = leves;
- for (int j = num3; j <= num4; j++)
- {
- AddHead(dgv, mytree, j, tb);
- }
- }
- mytree.Dispose();
- }
- }
- private void AddHead(DataGridView dgv, mytree myheader, int curlevel, PdfPTable tb)
- {
- //IL_01b8: Unknown result type (might be due to invalid IL or missing references)
- //IL_01bf: Expected O, but got Unknown
- //IL_01c1: Unknown result type (might be due to invalid IL or missing references)
- //IL_01c8: Expected O, but got Unknown
- if (dgv == null || dgv.ColumnCount <= 0)
- {
- return;
- }
- int columnCount = dgv.ColumnCount;
- checked
- {
- int[] array = new int[columnCount - 1 + 1];
- int[] array2 = new int[columnCount - 1 + 1];
- int num = 0;
- int num2 = columnCount - 1;
- for (int i = num; i <= num2; i++)
- {
- array[i] = i;
- array2[i] = dgv.Columns[i].DisplayIndex;
- }
- Array.Sort(array2, array);
- int num3 = (int)Math.Round((double)dgv.ColumnHeadersHeight / (double)myheader.GetLeves());
- int num4 = 0;
- int num5 = dgv.ColumnCount - 1;
- bool flag = true;
- for (int j = num4; j <= num5; j++)
- {
- if (!dgv.Columns[array[j]].Visible)
- {
- continue;
- }
- int num6 = myheader.GetCellHeightLevels(array[j], curlevel, isTopNodeFill: false, out flag);
- int cellWidthCols = myheader.GetCellWidthCols(array[j], curlevel);
- if (unchecked(num6 == 0 || cellWidthCols == 0))
- {
- if (num6 != 0)
- {
- }
- continue;
- }
- string nodeText = myheader.GetNodeText(array[j], curlevel);
- Font font = myheader.GetNodeFont(array[j], curlevel);
- if (font == null)
- {
- font = Module1.GetDGVHeaderFont(dgv.Columns[array[j]]);
- }
- Color cc = myheader.GetNodeForeColor(array[j], curlevel);
- if (cc.IsEmpty)
- {
- cc = Module1.GetDGVHeaderForeColor(dgv.Columns[array[j]]);
- }
- Color cc2 = myheader.GetNodeBackColor(array[j], curlevel);
- if (cc2.IsEmpty)
- {
- cc2 = Module1.GetDGVHeaderBackColor(dgv.Columns[array[j]]);
- }
- if (unchecked(cellWidthCols == 1 && num6 == 1))
- {
- _ = dgv.Columns[array[j]].Width;
- }
- else
- {
- _ = (int)Math.Round(myheader.GetCellWidth2(array[j], curlevel));
- }
- Phrase val = new Phrase(nodeText, GetPDFFont(font, cc));
- PdfPCell val2 = new PdfPCell(val);
- if (cellWidthCols != 0)
- {
- val2.Colspan = cellWidthCols;
- }
- if (num6 != 0)
- {
- val2.Rowspan = num6;
- }
- val2.Padding = 1f;
- ((Rectangle)val2).BorderColor = GetPDFColor(dgv.GridColor);
- val2.HorizontalAlignment = 1;
- val2.VerticalAlignment = 5;
- ((Rectangle)val2).BackgroundColor = GetPDFColor(cc2);
- if (num6 <= 0)
- {
- num6 = 1;
- }
- if (myratio >= 1f)
- {
- val2.FixedHeight = Module1.G_ruler.ConvertToPoint(num3 * num6, isx: false);
- }
- else
- {
- val2.MinimumHeight = Module1.G_ruler.ConvertToPoint(num3 * num6, isx: false);
- }
- tb.AddCell(val2);
- }
- }
- }
- private void AddRow(DataGridView dgv, int rowindex, PdfPTable tb)
- {
- //IL_0750: Unknown result type (might be due to invalid IL or missing references)
- //IL_0757: Expected O, but got Unknown
- //IL_0759: Unknown result type (might be due to invalid IL or missing references)
- //IL_0760: Expected O, but got Unknown
- //IL_065a: Unknown result type (might be due to invalid IL or missing references)
- //IL_0661: Expected O, but got Unknown
- //IL_0602: Unknown result type (might be due to invalid IL or missing references)
- //IL_0609: Expected O, but got Unknown
- //IL_05f6: Unknown result type (might be due to invalid IL or missing references)
- //IL_05fd: Expected O, but got Unknown
- //IL_0536: Unknown result type (might be due to invalid IL or missing references)
- //IL_053d: Expected O, but got Unknown
- if (dgv == null || dgv.RowCount <= 0 || rowindex >= dgv.RowCount || dgv.ColumnCount <= 0 || !dgv.Rows[rowindex].Visible)
- {
- return;
- }
- int columnCount = dgv.ColumnCount;
- checked
- {
- int[] array = new int[columnCount - 1 + 1];
- int[] array2 = new int[columnCount - 1 + 1];
- int num = 0;
- int num2 = columnCount - 1;
- for (int i = num; i <= num2; i++)
- {
- array[i] = i;
- array2[i] = dgv.Columns[i].DisplayIndex;
- }
- Array.Sort(array2, array);
- int height = dgv.Rows[rowindex].Height;
- int num3 = 1;
- int num4 = 0;
- int num5 = 0;
- int num6 = 0;
- int num7 = 0;
- int num8 = 1;
- int num9 = 0;
- int num10 = dgv.ColumnCount - 1;
- for (int j = num9; j <= num10; j++)
- {
- if (!dgv.Columns[array[j]].Visible)
- {
- continue;
- }
- num8 = 1;
- num3 = 1;
- num6 = 0;
- num4 = 0;
- num7 = 0;
- num6 = 0;
- num4 = 0;
- num5 = 0;
- float myheight = height;
- string text = Conversions.ToString(dgv.Rows[rowindex].Cells[array[j]].Tag);
- int num11 = 0;
- int firstrow = 0;
- int firstr = 0;
- switch (text)
- {
- default:
- {
- int firstcolumn = 0;
- int firstc = 0;
- switch (text)
- {
- default:
- num8 = 1;
- num3 = 1;
- num11 = dgv.Columns[array[j]].Width;
- break;
- case "合并":
- case "左上合并":
- case "左下合并":
- case "右上合并":
- case "右下合并":
- case "上边合并":
- case "下边合并":
- case "左边合并":
- case "右边合并":
- {
- float mywidth = 0f;
- mymerge.GetHVMergeWidthAndHeight(dgv, array[j], rowindex, ref mywidth, ref myheight, ref num7, ref num6, ref num4, ref num5, ref firstcolumn, ref firstrow, ref firstc, ref firstr);
- num8 = num6 + num7 + 1;
- num3 = num4 + num5 + 1;
- num11 = (int)Math.Round(mywidth);
- unchecked
- {
- if (num3 > 1 && num8 > 1)
- {
- if (!(num4 == 0 && num6 == 0))
- {
- if (num6 != 0)
- {
- }
- continue;
- }
- }
- else if (num3 > 1)
- {
- if (num4 != 0)
- {
- continue;
- }
- }
- else if (num8 > 1 && num6 != 0)
- {
- continue;
- }
- break;
- }
- }
- case "水平合并":
- case "#水平合并#":
- case "左合并":
- case "右合并":
- num11 = (int)Math.Round(mymerge.GetHMergeWidth(dgv, array[j], rowindex, ref num8, ref num6, ref num7, ref firstcolumn, ref firstc, iscancheckheight: true));
- if (num8 > 1 && num6 != 0)
- {
- continue;
- }
- break;
- }
- break;
- }
- case "垂直合并":
- case "#垂直合并#":
- case "上合并":
- case "下合并":
- myheight = mymerge.GetVMergeHeight(dgv, array[j], rowindex, ref num3, ref num5, ref num4, ref firstrow, ref firstr);
- num11 = dgv.Columns[array[j]].Width;
- if (num3 > 1 && num4 != 0)
- {
- continue;
- }
- break;
- }
- Font dGVCellFont = Module1.GetDGVCellFont(dgv.Rows[rowindex].Cells[array[j]]);
- Color dGVCellBackColor = Module1.GetDGVCellBackColor(dgv.Rows[rowindex].Cells[array[j]]);
- Color dGVCellForeColor = Module1.GetDGVCellForeColor(dgv.Rows[rowindex].Cells[array[j]]);
- Margins dGVCellPadding = Module1.GetDGVCellPadding(dgv.Rows[rowindex].Cells[j]);
- PdfPCell val;
- if (dgv.Columns[array[j]] is DataGridViewImageColumn)
- {
- if (dgv.Rows[rowindex].Cells[array[j]].Value != null)
- {
- if (dgv.Rows[rowindex].Cells[array[j]].FormattedValue != null)
- {
- Image instance = Image.GetInstance((Image)dgv.Rows[rowindex].Cells[array[j]].FormattedValue, BaseColor.WHITE);
- DataGridViewImageCell dataGridViewImageCell = (DataGridViewImageCell)dgv.Rows[rowindex].Cells[array[j]];
- DataGridViewImageCellLayout imageLayout = dataGridViewImageCell.ImageLayout;
- if (imageLayout == DataGridViewImageCellLayout.Stretch)
- {
- if (myratio >= 1f)
- {
- instance.ScaleAbsolute(Module1.G_ruler.ConvertToPoint(num11 - 1, isx: true) * myratio, Module1.G_ruler.ConvertToPoint(myheight - 1f, isx: false));
- }
- else
- {
- instance.ScaleAbsoluteWidth(Module1.G_ruler.ConvertToPoint(num11, isx: true) * myratio);
- }
- }
- else
- {
- instance.ScaleToFit(Module1.G_ruler.ConvertToPoint(num11, isx: true) * myratio, Module1.G_ruler.ConvertToPoint(myheight, isx: false));
- }
- val = new PdfPCell(instance);
- val.PaddingLeft = Module1.G_ruler.ConvertToPoint(dGVCellPadding.Left, isx: true);
- val.PaddingRight = Module1.G_ruler.ConvertToPoint(dGVCellPadding.Right, isx: true);
- val.PaddingBottom = Module1.G_ruler.ConvertToPoint(dGVCellPadding.Bottom, isx: false);
- val.PaddingTop = Module1.G_ruler.ConvertToPoint(dGVCellPadding.Top, isx: false);
- if ((val.PaddingRight == 0f) & (val.PaddingLeft == 0f) & (val.PaddingBottom == 0f) & (val.PaddingTop == 0f))
- {
- val.Padding = 0.5f;
- }
- }
- else
- {
- val = new PdfPCell();
- }
- }
- else
- {
- val = new PdfPCell();
- }
- }
- else if (dgv.Columns[array[j]] is DataGridViewCheckBoxColumn)
- {
- Bitmap dGVCheckBoxCellImage = Module1.getDGVCheckBoxCellImage(dgv.Rows[rowindex].Cells[array[j]], dGVCellBackColor);
- Image instance2 = Image.GetInstance((Image)dGVCheckBoxCellImage, BaseColor.WHITE);
- val = new PdfPCell(instance2);
- val.PaddingLeft = Module1.G_ruler.ConvertToPoint(dGVCellPadding.Left, isx: true);
- val.PaddingRight = Module1.G_ruler.ConvertToPoint(dGVCellPadding.Right, isx: true);
- val.PaddingBottom = Module1.G_ruler.ConvertToPoint(dGVCellPadding.Bottom, isx: false);
- val.PaddingTop = Module1.G_ruler.ConvertToPoint(dGVCellPadding.Top, isx: false);
- if ((val.PaddingRight == 0f) & (val.PaddingLeft == 0f) & (val.PaddingBottom == 0f) & (val.PaddingTop == 0f))
- {
- val.Padding = 0.5f;
- }
- dGVCheckBoxCellImage.Dispose();
- }
- else
- {
- string text2 = Conversions.ToString(dgv.Rows[rowindex].Cells[array[j]].FormattedValue);
- Phrase val2 = new Phrase(text2, GetPDFFont(dGVCellFont, dGVCellForeColor));
- val = new PdfPCell(val2);
- val.PaddingLeft = Module1.G_ruler.ConvertToPoint(dGVCellPadding.Left, isx: true);
- val.PaddingRight = Module1.G_ruler.ConvertToPoint(dGVCellPadding.Right, isx: true);
- val.PaddingBottom = Module1.G_ruler.ConvertToPoint(dGVCellPadding.Bottom, isx: false);
- val.PaddingTop = Module1.G_ruler.ConvertToPoint(dGVCellPadding.Top, isx: false);
- }
- ((Rectangle)val).BorderColor = GetPDFColor(dgv.GridColor);
- if (myratio >= 1f)
- {
- val.FixedHeight = Module1.G_ruler.ConvertToPoint(myheight, isx: false);
- }
- else
- {
- val.MinimumHeight = Module1.G_ruler.ConvertToPoint(myheight, isx: false);
- }
- ((Rectangle)val).BackgroundColor = GetPDFColor(dGVCellBackColor);
- val.Rowspan = num3;
- val.Colspan = num8;
- DataGridViewContentAlignment alignment = Module1.GetDGVCellStyle(dgv.Rows[rowindex].Cells[array[j]]).Alignment;
- if (alignment != DataGridViewContentAlignment.BottomCenter && alignment != DataGridViewContentAlignment.BottomLeft && alignment != DataGridViewContentAlignment.BottomRight)
- {
- if (alignment != DataGridViewContentAlignment.MiddleCenter && alignment != DataGridViewContentAlignment.MiddleLeft && alignment != DataGridViewContentAlignment.MiddleRight && alignment != 0)
- {
- val.VerticalAlignment = 4;
- }
- else
- {
- val.VerticalAlignment = 5;
- }
- }
- else
- {
- val.VerticalAlignment = 6;
- }
- DataGridViewContentAlignment alignment2 = Module1.GetDGVCellStyle(dgv.Rows[rowindex].Cells[array[j]]).Alignment;
- if (alignment2 != DataGridViewContentAlignment.BottomLeft && alignment2 != DataGridViewContentAlignment.MiddleLeft && alignment2 != DataGridViewContentAlignment.TopLeft && alignment2 != 0)
- {
- if (alignment2 != DataGridViewContentAlignment.BottomCenter && alignment2 != DataGridViewContentAlignment.MiddleCenter && alignment2 != DataGridViewContentAlignment.TopCenter)
- {
- val.HorizontalAlignment = 2;
- }
- else
- {
- val.HorizontalAlignment = 1;
- }
- }
- else
- {
- val.HorizontalAlignment = 0;
- }
- tb.AddCell(val);
- }
- }
- }
- private static BaseColor GetPDFColor(Color cc)
- {
- //IL_0001: Unknown result type (might be due to invalid IL or missing references)
- //IL_0007: Expected O, but got Unknown
- return new BaseColor(cc);
- }
- */
- }
- }
|