ميزة:
يدعم JXL الصينية بشكل جيد للغاية ، والعملية بسيطة ، والطريقة تعتمد على الاسم والمعنى.
JXL هي واجهة برمجة تطبيقات Java Pure ، والتي تعمل بشكل مثالي عبر المنصات. يمكن تشغيل الرمز على Windows أو Linux دون إعادة كتابة
يدعم جميع إصدارات Excel 95-2000 (يقال عبر الإنترنت أنه يمكن أن يدعم Excel 2007 في الوقت الحاضر ، لكنه لم يحاول بعد)
توليد التنسيق القياسي لـ Excel 2000
دعم الخط والرقم وعمليات التاريخ
قادرة على تعديل خصائص الخلية
يتم دعم الصور والمخططات ، لكن واجهة برمجة التطبيقات هذه لديها دعم محدود للرسومات والمخططات ، ويتعرف فقط على تنسيق PNG.
عيب:
دعم الصور غير الفعال وغير الناقص ، ودعم أقل قوة للتنسيقات من POI
قضية:
الأوقات سلسلة = (جديدة simpledateFormat ("YyyyMMDDHHMMSS")) // قائمة اسم الملف <logs> list = logsservice.selectForList (hql.toString ()) ؛ string path = request.getSession (). getServletContext (). getRealPath ("/") + "XLS/" + (new SimplEdateFormat ("yyyymmdd")). التنسيق (تاريخ جديد ()) ؛ ملف الملف = ملف جديد (مسار) ؛ // إنشاء if (! file.exists () &&! file.isdirectory ()) {file.mkdir () ؛ } response.setContentType ("application/vnd.ms-excel ؛ charset = utf-8") ؛ // // حدد نوع حفظ الملف. استجابة. setcharacterencoding ("UTF-8") ؛ ExportUtil.writer_log (طلب ، fname ، قائمة ، استجابة) ؛ // تحميل إلى محليطريقة تصدير الكاتب على النحو التالي
/*** إنشاء ملف excel وتصديره إلى الكمبيوتر المحلي* param fname اسم ملف* @param قائمة بالبيانات المراد طباعتها ، أي أن قائمة بيانات استعلامات قاعدة البيانات*/public static void constr_log استجابة. reset () ؛ // قم بمسح دفق الإخراج // فيما يلي بداية معالجة اسم الملف الصيني. else fname = new string (fname.getbytes ("utf-8") ، "ISO-8859-1") ؛ استجابة. استجابة. WritableWorkbook WOBBOK = Workbook.Createworkbook (OS) ؛ // إنشاء ملف excel file writablesheet = wbook.createeset ("سجل النظام" ، 0) ؛ // اسم ورقة العمل CellView CellView = جديد CellView () ؛ cellview.setautosize (true) ؛ // قم بتعيين sheet Seint.setColumnView (0 ، 8) ؛ // اضبط عرض الخلية ، 0 هو رقم العمود ، 8 هو Sheet.SetColumnView (1 ، 20) ؛ // اضبط عرض الخلية ، 1 هو رقم العمود ، 20 هو Sheet.SetColumnView (2 ، 24) ؛ sheet.setColumnView (3 ، 20) ؛ sheet.setColumnView (4 ، 30) ؛ sheet.setColumnView (5 ، 13) ؛ sheet.setColumnView (6 ، 15) ؛ sheet.setColumnView (7 ، 32) ؛ sheet.setColumnView (8 ، 15) ؛ // set excel font fontablefont wfont = new writablefont (writablefont.createfont ("宋体") ، 22 ، critablefont.bold ، false ، jxl.format.underlinestyle.no_underline ، jxl.format.colour.black) ؛ . // إضافة خلية الخطاب titleformat.setalignment (alignment.centre) ؛ // تعيين محاذاة توسيط النص ؛ String [] title = {"system log"} ؛ // قم بتعيين رأس جدول Excel Table Start (int i = 0 ؛ i <title.length ؛ i ++) {// ما تم استيراده هنا هو استيراد jxl.write.label ؛ تسمية exceltitle = new label (i ، 0 ، title [i] ، titleformat) ؛ // cell content // parameter order: start colde ، start row ، end column ، end row sheet.mergecells (0 ، 0 ، 8 ، 0) ؛ // الموقع ، أي صف ، أي ورقة عمود. // إضافة معلومات الخلية} // قم بتعيين نهاية رأس جدول excel // الصف الأول ، أي وقت العرض ، المعلمات: (العمود ، الصف ، المحتوى) writablefont wfonttime = new writablefont (writablefont.createfont ("宋体") ، 11 ، abtablefont.no_bold ، false ، jxl.format.formateleatele.no_enderline ، jxl.format.colour.black) ؛ // set cell font style writableCellformat Titletime = new WritableCellFormat (wfonttime) ؛ // إضافة خلية font titletime.setalignment (محاذاة. رايت) ؛ // تعيين محاذاة توسيط النص ؛ DateFormat df = new SimplEdateFormat ("Yyyy-MM-DD") ؛ // sheet.setColumnView (1 ، CellView) ؛ . // cell content // sheet.mergecells (16 ، 1 ، 18 ، 1) ؛ // الموقع ، وهو الصف والعمود في الصف ، أي الموضع المدمج. إذا لم يكن هناك دمج ، فلا يمكنك كتابة Sheet.addcell (contentDate) ؛ // إضافة معلومات الخلية // نهاية الصف الأول // يوضح الصف الثاني شريط العنوان Condition Frablefont wfont2 = new writablefont (writablefont.createfont ("宋体") ، 11 ، abtablefont.bold ، false ، jxl.format.underlinestle.no_underline ، jxl.format.colour.black) ؛ . // إضافة خلية الخطاب titleformat2.setBorder (border.all ، borderlinestyle.thin) ؛ // تعيين خط الحدود الصلبة ؛ titleformat2.setalignment (alignment.centre) ؛ // تعيين المحاذاة المتمركزة للنص ؛ titleformat2.setverticalAlignment (verticalalignment.centre) ؛ // تعيين التركيز العمودي ؛ Label Content2a = New Label (0 ، 2 ، "Number Number" ، titleformat2) ؛ // Cell Content-1st Grid Label Content2B = New Label (1 ، 2 ، "اسم المستخدم" ، titleformat2) ؛ // Cell Content-2nd Grid Label Content2C = New Label (2 ، 2 ، "Record Time" ، titleformat2) ؛ // Cell Content-3rd Grid Label Content2C = New Label (2 ، 2 ، "Record Time" ، titleformat2) ؛ // Cell Content-3rd Grid Label Content2C = New Label (2 ، 2 ، "Record Time" ، titleformat2) ؛ // Cell Content-3rd Grid Label Content2D = New Label (3 ، 2 ، "Operation Module" ، titleformat2) ؛ // Cell Content-4th Grid Label Content2E = New Label (4 ، 2 ، "Operation Content" ، titleformat2) ؛ // Cell Content-5th Grid Label Content2F = New Label (5 ، 2 ، "Operation Action" ، titleformat2) ؛ // Cell Content-6th Grid Label Content2G = New Label (6 ، 2 ، "Operator IP" ، titleformat2) ؛ // Cell Content-7th Grid Label Content2H = New Label (7 ، 2 ، "Operation Organization" ، titleformat2) ؛ // Cell Content-8th Grid Label Content2i = New Label (8 ، 2 ، "note" ، titleformat2) ؛ // Cell Content-9th Grid sheet.mergecells (0 ، 1 ، 8 ، 1) ؛ /*Sheet.mergecells(0 ، 2 ، 0 ، 4) ؛ // الموقع ، وهو الصف والعمود في الصف ، أي موضع الدمج ، إذا لم يكن هناك دمج ، لا يمكنك كتابته ؛ (هنا هو سطر البداية 3 إلى الصف 5 ، العمود 1) sheet.mergecells (1 ، 2 ، 1 ، 4) ؛ // الموقع ، وهو الصف والعمود في الصف ، أي موضع الدمج ، إذا لم يكن هناك دمج ، لا يمكنك كتابته ؛ (هنا هو سطر البداية 3 إلى الصف 5 ، العمود 2) sheet.mergecells (2 ، 2 ، 2 ، 4) ؛ // الموقع ، وهو الصف والعمود في الصف ، أي الموضع المدمج ، إذا لم يكن هناك دمج ، لا يمكنك كتابته ؛ (هنا هو سطر البداية 3 إلى الصف 5 ، العمود 3) sheet.mergecells (3 ، 2 ، 3 ، 4) ؛ // الموقع ، وهو الصف والعمود في الصف ، أي الموضع المدمج ، إذا لم يكن هناك دمج ، لا يمكنك كتابته ؛ (هنا هو سطر البداية 3 إلى الصف 5 ، العمود 4) sheet.mergecells (4 ، 2 ، 4 ، 4) ؛ // الموقع ، وهو الصف والعمود في الصف ، أي الموضع المدمج ، إذا لم يكن هناك دمج ، لا يمكنك كتابته ؛ (هنا هو سطر البداية 3 إلى الصف 5 ، العمود 5) sheet.mergecells (5 ، 2 ، 5 ، 4) ؛ // الموقع ، وهو الصف والعمود في الصف ، أي الموضع المدمج ، إذا لم يكن هناك دمج ، لا يمكنك كتابته ؛ (هنا هو سطر البداية 3 إلى الصف 5 ، العمود 6) sheet.mergecells (6 ، 2 ، 6 ، 4) ؛ // الموقع ، وهو الصف والعمود في الصف ، أي الموضع المدمج ، إذا لم يكن هناك دمج ، لا يمكنك كتابته ؛ (هنا هو سطر البداية 3 إلى الصف 5 ، العمود 7) sheet.mergecells (7 ، 2 ، 7 ، 4) ؛ // الموقع ، وهو الصف والعمود في الصف ، أي الموضع المدمج ، إذا لم يكن هناك دمج ، لا يمكنك كتابته ؛ (هنا هو سطر البداية 3 إلى الصف 5 ، العمود 8) sheet.mergecells (8 ، 2 ، 8 ، 4) ؛ // الموقع ، وهو الصف والعمود في الصف ، أي موضع الدمج. إذا لم يكن هناك دمج ، لا يمكنك كتابته ؛ (هنا هو سطر البداية 3 إلى الصف 5 ، العمود 9) sheet.mergecells (9 ، 2 ، 9 ، 4) ؛ // الموقع ، وهو الصف والعمود في الصف ، أي موضع الدمج. إذا لم يكن هناك دمج ، لا يمكنك كتابته ؛ (هنا هو سطر البداية 3 إلى الصف 5 ، العمود 10) sheet.mergecells (10 ، 2 ، 12 ، 3) ؛ // الموقع ، وهو الصف والعمود في الصف ، أي موضع الدمج. إذا لم يكن هناك دمج ، لا يمكنك كتابته ؛ (هنا هو سطر البداية 3 إلى الصف 4 ، العمود 11-13) sheet.mergecells (13 ، 2 ، 15 ، 3) ؛ // الموقع ، الذي يوجد فيه الصف والعمود في الصف الأول ، أي الموضع المدمج ، إذا لم يكن هناك دمج ، لا يمكنك كتابته ؛ (هنا هو سطر البداية 3 إلى الصف 4 ، الأعمدة 14-16) sheet.mergecells (16 ، 2 ، 16 ، 4) ؛ // الموقع ، الذي يوجد فيه الصف والعمود في الصف الأول ، أي الموضع المدمج ، إذا لم يكن هناك دمج ، لا يمكنك كتابته ؛ (هنا هو سطر البداية 3 إلى الصف 5 ، العمود 17) sheet.mergecells (17 ، 2 ، 17 ، 4) ؛ // الموقع ، الذي يوجد فيه الصف والعمود في الصف الأول ، أي الموضع المدمج ، إذا لم يكن هناك دمج ، لا يمكنك كتابته ؛ (هنا هو سطر البداية 3 إلى الصف 5 ، العمود 18) Sheet.mergecells (18 ، 2 ، 18) ؛ // الموقع ، وهو الصف والعمود في الصف الأول ، أي الموضع المدمج. إذا لم يكن هناك دمج ، لا يمكنك كتابته ؛ (هنا هو سطر البداية من 3 إلى 5 ، العمود 19) */ sheet.addcell (content2a) ؛ // إضافة أول ورقة معلومات الخلية. addcell (content2b) ؛ // إضافة ورقة معلومات الخلية الثانية. addcell (content2c) ؛ // إضافة ورقة معلومات الخلية الثالثة. addcell (content2d) ؛ // إضافة ورقة معلومات الخلية الرابعة. addcell (content2e) ؛ // إضافة ورقة معلومات الخلية الخامسة. addcell (content2f) ؛ // إضافة ورقة معلومات الخلية السادسة. addcell (content2g) ؛ // إضافة ورقة معلومات الخلية السابعة. addcell (content2h) ؛ // إضافة ورقة معلومات الخلية الثامنة. addcell (content2i) ؛ // أضف معلومات الخلية التاسعة التي تم كتابتها wf = new writablefont (writablefont.createfont ("安安") ، 11 ، critablefont.no_bold ، false ، jxl.format.underlinestle.no_underline ، jxl.format.colour.black) ؛ // قم بتعيين نمط خط الخلية writableCellFormat wcf = new WritableCellFormat (WF) ؛ // إضافة خلية font wcf.setborder (border.all ، borderlinestyle.thin) ؛ // تعيين خط الحدود الصلبة ؛ wcf.setverticalAlignment (verticalalignment.centre) ؛ // تعيين المحاذاة الرأسية wcf.setalignment (alignment.centre) ؛ // تعيين محاذاة تركز أفقية للنص ؛ wcf.setWrap (صواب) ؛ // wrap tomatic wrap writablefont wf1 = new writablefont (writablefont.createfont ("安体") ، 11 ، critablefont.no_bold ، false ، jxl.format.underlinestle.no_underline ، jxl.format.colour.black) ؛ . // إضافة خلية font wcf1.setBorder (border.left ، borderlinestyle.thin) ؛ // تعيين خط الحدود الصلبة ؛ wcf1.setverticalIngenment (verticalalignment.centre) ؛ // تعيين المحاذاة الرأسية wcf1.setalignment (محاذاة. centre) ؛ // تعيين محاذاة تركز أفقية للنص ؛ // المعلومات التي تم الحصول عليها بواسطة قاعدة بيانات الحلقة التالية int c = 1 ؛ // عدد السطر من Excel المستخدمة لحلق Iterator It = list.iterator () ؛ بينما (it.hasnext ()) {logs tc = (logs) it.next () ؛ DateFormat dfmt = new SimplEdateFormat ("yyyy.mm") ؛ String Xh = string.valueof (c) ؛ if (xh == null) {xh = "" ؛ } label content0 = new label (0 ، c+2 ، xh ، wcf) ؛ // اسم سلسلة الرقم التسلسلي = tc.getUserName () ؛ if (name == null) {name = "" ؛ } label content1 = new label (1 ، c+2 ، name ، wcf) ؛ // username string xrpresent = tc.getLogTime () ؛ if (xrpresent == null) {xrpresent = "" ؛ } label content2 = new label (2 ، c+2 ، xrpresent ، wcf) ؛ // تسجيل وقت سلسلة czModel = tc.getModel () ؛ if (czModel == null) {czModel = "" ؛ } label content3 = new label (3 ، c+2 ، czmodel ، wcf) ؛ // Operation module string sex = tc.getContent () ؛ if (sex == null) {sex = "" ؛ } label content4 = new label (4 ، c+2 ، sex ، wcf) ؛ // عملية المحتوى سلسلة عيد ميلاد = tc.getOperate () ؛ if (عيد ميلاد == null) {birthday = "" ؛ } label content5 = New Label (5 ، C+2 ، Birthday ، WCF) ؛ // Operation Action String Nation = tc.getip () ؛ if (nation == null) {nation = "" ؛ } label content6 = New Label (6 ، C+2 ، Nation ، WCF) ؛ // Operator IP String Origin = TC.GetorGname () ؛ if (Origin == null) {Origin = "" ؛ } label content7 = New Label (7 ، C+2 ، Origin ، WCF) ؛ // أو string string blace = tc.getRemark () ؛ if (b place == null) {bplace = "" ؛ } label content8 = new label (8 ، c+2 ، b place ، wcf) ؛ // ملاحظة سلسلة abc = "" ؛ content content 9 = تسمية جديدة (9 ، C+2 ، ABC ، WCF1) ؛ // ملاحظة sheet.setRowView (C+2 ، 600) ؛ // قم بتعيين ورقة ارتفاع الخط. sheet.setRowView (C+2 ، 600) ؛ sheet.setRowView (C+2 ، 600) ؛ sheet.setRowView (C+2 ، 600) ؛ sheet.setRowView (C+2 ، 600) ؛ sheet.setRowView (C+2 ، 600) ؛ sheet.setRowView (C+2 ، 600) ؛ sheet.setRowView (C+2 ، 600) ؛ sheet.mergecells (0 ، c+2 ، 0 ، c+2) ؛ // mergecells (1 ، c+2 ، 0 ، c+2) ؛ // mergecells (a ، b ، c ، d) sheet sheet.mergecells (2 ، c+2 ، 0 ، c+2) ؛ // ورقة رقم عمود الخلية. mergecells (3 ، C+2 ، 0 ، C+2) ؛ // b number number sheet.mergecells (4 ، c+2 ، 0 ، c+2) ؛ // C بدءًا من الخلية [A ، B] ، اندمج لأسفل إلى ورقة العمود C (5 ، C+2 ، 0 ، C+2) ؛ // d من الخلية [a ، b] ، اندمج لأسفل إلى الصف d sheet.mergecells (6 ، c+2 ، 0 ، c+2) ؛ sheet.mergecells (7 ، c+2 ، 0 ، c+2) ؛ sheet.mergecells (8 ، c+2 ، 0 ، c+2) ؛ sheet.mergecells (9 ، c+2 ، 0 ، c+2) ؛ sheet.addcell (content0) ؛ sheet.addcell (content1) ؛ sheet.addcell (content2) ؛ sheet.addcell (content3) ؛ sheet.addcell (content4) ؛ sheet.addcell (content5) ؛ sheet.addcell (content6) ؛ sheet.addcell (content7) ؛ sheet.addcell (content8) ؛ sheet.addcell (content9) ؛ C ++ ؛ } wbook.write () ؛ // اكتب إلى ملف wbook.close () ؛ OS.Close () ؛ } catch (استثناء e) {رمي new paikeException ("خطأ في ملف التصدير") ؛ }}المثال أعلاه شرح لبيانات تصدير JXL إلى Excel هو كل المحتوى الذي أشاركه معك. آمل أن تتمكن من إعطائك مرجعًا وآمل أن تتمكن من دعم wulin.com أكثر.