├── .gitignore ├── ExcelViewLib ├── .gitignore ├── build.gradle ├── consumer-rules.pro ├── libs │ ├── log4j-api-2.14.1.jar │ ├── poi-5.1.0.jar │ ├── poi-ooxml-5.1.0.jar │ └── poi-ooxml-full-5.1.0.jar ├── proguard-rules.pro ├── publish.gradle └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── xt │ │ └── excelview │ │ └── lib │ │ ├── control │ │ ├── ExcelControlImpl.java │ │ └── ExcelControlInter.java │ │ ├── dialog │ │ ├── ExcelEditDialog.java │ │ ├── KeyBoardCenterDialog.java │ │ └── KeyBoardDialog.java │ │ ├── util │ │ ├── DeviceUtil.java │ │ ├── ImageUtil.java │ │ └── StringUtil.java │ │ └── view │ │ ├── CommonSeekBar.java │ │ ├── CommonVerticalSeekBar.java │ │ └── ExcelView.java │ └── res │ ├── color │ ├── color_select_2072eb_33333.xml │ ├── color_select_2870f6_666666.xml │ ├── color_select_2870f6_999999.xml │ └── selector_blue_gray_textcolor.xml │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ ├── common_button_b3b8c1.xml │ ├── common_dialog_keyboard_close.png │ ├── common_divider_ffffff.xml │ ├── common_execl_range_icon.png │ ├── common_keyboard_btn_selector.xml │ ├── common_keyboard_del2.png │ ├── common_keyboard_item_selector.xml │ ├── common_progress_drag_button.png │ ├── common_rect_0062ff_hollow.xml │ ├── common_rect_c9ced4_hollow.xml │ ├── common_rect_r2_2870f6_shadow.xml │ ├── common_seekbar_style2.xml │ ├── ic_launcher_background.xml │ └── original_common_corner_ffffff_r7.xml │ ├── layout │ ├── common_dialog_keyboard_center_layout.xml │ └── common_dialog_keyboard_layout.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── mipmap-mdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── mipmap-xhdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── mipmap-xxhdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── mipmap-xxxhdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── values-land │ └── dimens.xml │ ├── values-w1240dp │ └── dimens.xml │ ├── values-w600dp │ └── dimens.xml │ └── values │ ├── attr.xml │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── themes.xml ├── LICENSE ├── PoiLib ├── .gitignore ├── build.gradle ├── consumer-rules.pro ├── libs │ ├── commons-collections4-4.4.jar │ ├── commons-compress-1.21.jar │ ├── commons-io-2.11.0.jar │ ├── commons-math3-3.6.1.jar │ ├── log4j-api-2.14.1(1).jar │ ├── poi-5.1.0.jar │ ├── poi-ooxml-5.1.0(1).jar │ ├── poi-ooxml-full-5.1.0(1).jar │ └── xmlbeans-5.0.2(1).jar ├── proguard-rules.pro ├── publish.gradle └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ ├── com │ │ └── xt │ │ │ └── excelview │ │ │ └── poi │ │ │ └── poi │ │ │ └── PoiUtil.java │ └── org │ │ └── apache │ │ └── xmlbeans │ │ └── impl │ │ └── store │ │ └── Locale.java │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ ├── common_button_b3b8c1.xml │ ├── common_dialog_keyboard_close.png │ ├── common_divider_ffffff.xml │ ├── common_execl_range_icon.png │ ├── common_keyboard_btn_selector.xml │ ├── common_keyboard_del2.png │ ├── common_keyboard_item_selector.xml │ ├── common_progress_drag_button.png │ ├── common_rect_0062ff_hollow.xml │ ├── common_rect_c9ced4_hollow.xml │ ├── common_rect_r2_2870f6_shadow.xml │ ├── common_seekbar_style2.xml │ ├── ic_launcher_background.xml │ └── original_common_corner_ffffff_r7.xml │ └── values │ ├── dimens.xml │ └── strings.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── assets │ ├── demo.xls │ └── demo.xlsx │ ├── java │ └── com │ │ └── xt │ │ └── excelview │ │ ├── Fragment1.java │ │ ├── Fragment2.java │ │ ├── Fragment3.java │ │ ├── MainActivity.java │ │ ├── custom │ │ └── CustomControlImpl.java │ │ └── util │ │ └── IOHelper.java │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ └── ic_launcher_background.xml │ ├── layout │ ├── activity_main.xml │ ├── fragment_first.xml │ ├── fragment_haha.xml │ ├── fragment_second.xml │ └── fragment_third.xml │ ├── menu │ └── menu_main.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── mipmap-mdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── mipmap-xhdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── mipmap-xxhdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── mipmap-xxxhdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── values-zh │ └── strings.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── themes.xml ├── build.gradle ├── gradle.properties ├── pics ├── img │ ├── desc.png │ ├── drag.gif │ ├── edit.gif │ ├── rangselect.gif │ └── unrangselect.gif └── mp4 │ ├── drag.mp4 │ ├── edit.mp4 │ ├── rangeselect.mp4 │ └── unselectrange.mp4 ├── sample ├── .gitignore ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ ├── assets │ ├── demo.xls │ └── demo.xlsx │ ├── java │ └── com │ │ └── xt │ │ └── excelview │ │ ├── Fragment1.java │ │ ├── Fragment2.java │ │ ├── Fragment3.java │ │ ├── MainActivity.java │ │ ├── custom │ │ └── CustomControlImpl.java │ │ └── util │ │ └── IOHelper.java │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ └── ic_launcher_background.xml │ ├── layout │ ├── activity_main.xml │ ├── fragment_first.xml │ ├── fragment_haha.xml │ ├── fragment_second.xml │ └── fragment_third.xml │ ├── menu │ └── menu_main.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── mipmap-mdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── mipmap-xhdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── mipmap-xxhdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── mipmap-xxxhdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── values-zh │ └── strings.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── themes.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/ 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | .cxx 10 | local.properties 11 | gradle/ 12 | gradlew 13 | gradlew.bat 14 | -------------------------------------------------------------------------------- /ExcelViewLib/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /ExcelViewLib/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.library' 3 | } 4 | 5 | android { 6 | compileSdk 31 7 | 8 | defaultConfig { 9 | minSdk 26 10 | targetSdk 31 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 15 | consumerProguardFiles "consumer-rules.pro" 16 | } 17 | 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | compileOptions { 25 | sourceCompatibility JavaVersion.VERSION_1_8 26 | targetCompatibility JavaVersion.VERSION_1_8 27 | } 28 | } 29 | 30 | dependencies { 31 | /** 32 | * poi 33 | */ 34 | // api project(':poi-ooxml') 35 | // implementation project(path: ':poi', configuration: 'archives') 36 | // compileOnly project(path: ':poi-ooxml', configuration: 'archives') 37 | // compileOnly project(path: ':poi-ooxml-full', configuration: 'archives') 38 | // compileOnly project(path: ':poi-scratchpad', configuration: 'archives') 39 | // implementation "org.apache.logging.log4j:log4j-core:${log4jVersion}" 40 | 41 | // implementation files('*.jar') 42 | // implementation 'stax:stax-api:1.0.1' 43 | // api fileTree(dir: 'libs', include: ['*.jar']) 44 | // implementation 'androidx.appcompat:appcompat:1.2.0' 45 | // implementation 'com.google.android.material:material:1.3.0' 46 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 47 | } 48 | 49 | ext { 50 | PUBLISH_ARTIFACT_ID = 'excelview' 51 | } 52 | apply from: 'publish.gradle' -------------------------------------------------------------------------------- /ExcelViewLib/consumer-rules.pro: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/ExcelViewLib/consumer-rules.pro -------------------------------------------------------------------------------- /ExcelViewLib/libs/log4j-api-2.14.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/ExcelViewLib/libs/log4j-api-2.14.1.jar -------------------------------------------------------------------------------- /ExcelViewLib/libs/poi-5.1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/ExcelViewLib/libs/poi-5.1.0.jar -------------------------------------------------------------------------------- /ExcelViewLib/libs/poi-ooxml-5.1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/ExcelViewLib/libs/poi-ooxml-5.1.0.jar -------------------------------------------------------------------------------- /ExcelViewLib/libs/poi-ooxml-full-5.1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/ExcelViewLib/libs/poi-ooxml-full-5.1.0.jar -------------------------------------------------------------------------------- /ExcelViewLib/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /ExcelViewLib/publish.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'maven-publish' 2 | apply plugin: 'signing' 3 | 4 | task androidSourcesJar(type: Jar) { 5 | classifier = 'sources' 6 | from android.sourceSets.main.java.source 7 | 8 | exclude "**/R.class" 9 | exclude "**/BuildConfig.class" 10 | } 11 | 12 | ext { 13 | PUBLISH_GROUP_ID = 'io.github.september26' 14 | PUBLISH_ARTIFACT_ID = 'excelview' 15 | PUBLISH_VERSION = '0.9.4' 16 | } 17 | //ext { 18 | // PUBLISH_GROUP_ID = 'com.sunsta.livery' 19 | // PUBLISH_ARTIFACT_ID = 'livery' 20 | // PUBLISH_VERSION = '1.2.0' 21 | //} 22 | 23 | ext["signing.keyId"] = '' 24 | ext["signing.password"] = '' 25 | ext["signing.secretKeyRingFile"] = '' 26 | ext["ossrhUsername"] = '' 27 | ext["ossrhPassword"] = '' 28 | 29 | File secretPropsFile = project.rootProject.file('local.properties') 30 | if (secretPropsFile.exists()) { 31 | println "Found secret props file, loading props" 32 | Properties p = new Properties() 33 | p.load(new FileInputStream(secretPropsFile)) 34 | p.each { name, value -> 35 | ext[name] = value 36 | println ext[name] 37 | } 38 | } else { 39 | println "No props file, loading env vars" 40 | } 41 | publishing { 42 | publications { 43 | release(MavenPublication) { 44 | // The coordinates of the library, being set from variables that 45 | // we'll set up in a moment 46 | groupId PUBLISH_GROUP_ID 47 | artifactId PUBLISH_ARTIFACT_ID 48 | version PUBLISH_VERSION 49 | 50 | // Two artifacts, the `aar` and the sources 51 | artifact("$buildDir/outputs/aar/${project.getName()}-release.aar") 52 | artifact androidSourcesJar 53 | 54 | // Self-explanatory metadata for the most part 55 | pom { 56 | name = PUBLISH_ARTIFACT_ID 57 | description = 'excelView poi' 58 | // If your project has a dedicated site, use its URL here 59 | url = 'https://github.com/September26/ExcelView' 60 | licenses { 61 | license { 62 | //协议类型,一般默认Apache License2.0的话不用改: 63 | name = 'The Apache License, Version 2.0' 64 | url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' 65 | } 66 | } 67 | developers { 68 | developer { 69 | id = '5694209@qq.com' 70 | name = ossrhUsername 71 | email = '5694209@qq.com' 72 | } 73 | } 74 | // Version control info, if you're using GitHub, follow the format as seen here 75 | scm { 76 | //修改成你的Git地址: 77 | connection = 'scm:git:github.com/September26/ExcelView.git' 78 | developerConnection = 'scm:git:ssh://github.com/September26/ExcelView.git' 79 | //分支地址: 80 | url = 'https://github.com/September26/ExcelView' 81 | } 82 | // A slightly hacky fix so that your POM will include any transitive dependencies 83 | // that your library builds upon 84 | withXml { 85 | def dependenciesNode = asNode().appendNode('dependencies') 86 | 87 | project.configurations.implementation.allDependencies.each { 88 | if (it.name != 'unspecified') { 89 | def dependencyNode = dependenciesNode.appendNode('dependency') 90 | dependencyNode.appendNode('groupId', it.group) 91 | dependencyNode.appendNode('artifactId', it.name) 92 | dependencyNode.appendNode('version', it.version) 93 | } 94 | } 95 | } 96 | } 97 | } 98 | } 99 | repositories { 100 | // The repository to publish to, Sonatype/MavenCentral 101 | maven { 102 | // This is an arbitrary name, you may also use "mavencentral" or 103 | // any other name that's descriptive for you 104 | name = "mavenCentral" 105 | 106 | def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" 107 | def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/" 108 | // You only need this if you want to publish snapshots, otherwise just set the URL 109 | // to the release repo directly 110 | url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl 111 | 112 | // The username and password we've fetched earlier 113 | credentials { 114 | username ossrhUsername 115 | password ossrhPassword 116 | } 117 | } 118 | } 119 | } 120 | signing { 121 | sign publishing.publications 122 | } -------------------------------------------------------------------------------- /ExcelViewLib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/java/com/xt/excelview/lib/control/ExcelControlImpl.java: -------------------------------------------------------------------------------- 1 | package com.xt.excelview.lib.control; 2 | 3 | import android.content.Context; 4 | import android.graphics.Color; 5 | import android.graphics.RectF; 6 | import android.view.Gravity; 7 | import android.view.View; 8 | import android.widget.SeekBar; 9 | import android.widget.Toast; 10 | 11 | import com.xt.excelview.lib.dialog.ExcelEditDialog; 12 | import com.xt.excelview.lib.dialog.KeyBoardCenterDialog; 13 | import com.xt.excelview.lib.dialog.KeyBoardDialog; 14 | import com.xt.excelview.lib.util.DeviceUtil; 15 | import com.xt.excelview.lib.view.ExcelView; 16 | 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | 20 | /** 21 | * 维护关系ExcelView和Model的关系 22 | * 23 | * @author lxl 24 | */ 25 | public class ExcelControlImpl implements ExcelControlInter { 26 | 27 | protected ExcelView excelView; 28 | protected SeekBar barX; 29 | protected SeekBar barY; 30 | protected View.OnClickListener listener; 31 | protected int dipUnit = 3; 32 | protected Context context; 33 | protected int[] mSelectRange; 34 | 35 | public ExcelControlImpl(ExcelView excelView, View.OnClickListener listener) { 36 | this(excelView, null, null, listener); 37 | } 38 | 39 | public ExcelControlImpl(ExcelView excelView, SeekBar barX, SeekBar barY, View.OnClickListener listener) { 40 | this.excelView = excelView; 41 | this.barX = barX; 42 | this.barY = barY; 43 | this.listener = listener; 44 | this.context = excelView.getContext(); 45 | if (barY != null) { 46 | barY.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 47 | 48 | @Override 49 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 50 | excelView.notifyStartXY(-1, progress); 51 | } 52 | 53 | @Override 54 | public void onStartTrackingTouch(SeekBar seekBar) { 55 | 56 | } 57 | 58 | @Override 59 | public void onStopTrackingTouch(SeekBar seekBar) { 60 | 61 | } 62 | }); 63 | } 64 | if (barX != null) { 65 | barX.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 66 | 67 | @Override 68 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 69 | excelView.notifyStartXY(progress, -1); 70 | } 71 | 72 | @Override 73 | public void onStartTrackingTouch(SeekBar seekBar) { 74 | 75 | } 76 | 77 | @Override 78 | public void onStopTrackingTouch(SeekBar seekBar) { 79 | 80 | } 81 | }); 82 | } 83 | } 84 | 85 | 86 | /** 87 | * 通过bind使页面和业务逻辑脱钩 88 | * 通过重写,实现不一样的业务逻辑 89 | */ 90 | public void bindData(ExcelView.TableValueModel model) { 91 | excelView.setCallBack(new ExcelView.SelectCallBack() { 92 | 93 | @Override 94 | public void rangSelectCallBackByCoord(RectF selectRectF, int[] selectRange) { 95 | int popWidth = dipUnit * 222; 96 | int popHeight = dipUnit * 24; 97 | ExcelEditDialog popWin = new ExcelEditDialog(context, popWidth, popHeight); 98 | ExcelEditDialog.DialogModel dialogModel = new ExcelEditDialog.DialogModel(); 99 | ArrayList list = new ArrayList<>(); 100 | list.add("复制"); 101 | list.add("粘贴"); 102 | list.add("加"); 103 | list.add("减"); 104 | list.add("乘"); 105 | list.add("除"); 106 | list.add("编辑"); 107 | dialogModel.setDataList(list); 108 | popWin.bindData(dialogModel, new ExcelEditDialog.ClickCallBack() { 109 | @Override 110 | public void clickByIndex(int index) { 111 | popWin.dismiss(); 112 | if (index == 0) { 113 | mSelectRange = selectRange.clone(); 114 | } else if (index == 1) { 115 | //粘贴 116 | List> arrayList = new ArrayList<>(); 117 | int startColumn = mSelectRange[0]; //第几列,X轴 118 | int startRow = mSelectRange[1]; //第几行,Y轴 119 | int endColumn = mSelectRange[2]; 120 | int endRow = mSelectRange[3]; 121 | for (int row = startRow; row < endRow; row++) { 122 | List line = model.dataList.get(row); 123 | ArrayList doubles = new ArrayList<>(line.subList(startColumn, endColumn + 1)); 124 | arrayList.add(doubles); 125 | } 126 | excelView.notifyDataChangeByRange(selectRange[1], selectRange[0], arrayList); 127 | mSelectRange = null; 128 | } else { 129 | //唤起键盘 130 | showKeyboard(model, selectRange, index - 1); 131 | } 132 | } 133 | }); 134 | popWin.showAtLocation(excelView, Gravity.TOP | Gravity.LEFT, (int) ((selectRectF.left + selectRectF.right - popWidth) / 2), (int) (selectRectF.top + 10 - popHeight)); 135 | } 136 | }); 137 | excelView.notifyDataChange(model); 138 | } 139 | 140 | /** 141 | * 通过重写,实现不一样的业务逻辑 142 | */ 143 | public void showKeyboard(ExcelView.TableValueModel tableModel, int[] selectRange, int selectType) { 144 | List> dataList = tableModel.dataList; 145 | KeyBoardDialog popWin = new KeyBoardDialog(context, DeviceUtil.getScreenSize(context)[0], dipUnit * 137); 146 | KeyBoardDialog.DialogModel dialogModel = new KeyBoardDialog.DialogModel(); 147 | dialogModel.setType(selectType); 148 | popWin.bindData(dialogModel, new KeyBoardDialog.SelectCallBack() { 149 | @Override 150 | public void selectByType(int type, double value) { 151 | 152 | if (type == KeyBoardCenterDialog.TYPE_DIVISION && value == 0.0) { 153 | Toast.makeText(context, "不能除以0,请重新输入", Toast.LENGTH_SHORT).show(); 154 | return; 155 | } 156 | int startColumn = selectRange[0]; 157 | int startRow = selectRange[1]; 158 | int endColumn = selectRange[2]; 159 | int endRow = selectRange[3]; 160 | //针对数据进行批量处理 161 | for (int i = 0; i < dataList.size(); i++) { 162 | if (i < startRow || i > endRow) { 163 | continue; 164 | } 165 | for (int j = startColumn; j <= endColumn; j++) { 166 | Double old = dataList.get(i).get(j); 167 | Double newValue = 0.0; 168 | switch (type) { 169 | case KeyBoardCenterDialog.TYPE_ADD: 170 | newValue = old + value; 171 | break; 172 | case KeyBoardCenterDialog.TYPE_SUB: 173 | newValue = old - value; 174 | break; 175 | case KeyBoardCenterDialog.TYPE_MULTI: 176 | newValue = old * value; 177 | break; 178 | case KeyBoardCenterDialog.TYPE_DIVISION: 179 | newValue = old / value; 180 | break; 181 | case KeyBoardCenterDialog.TYPE_ASSIGN: 182 | newValue = value; 183 | } 184 | dataList.get(i).set(j, newValue); 185 | } 186 | } 187 | excelView.notifyDataColor(selectRange, Color.RED); 188 | excelView.notifyDataChange(tableModel); 189 | } 190 | }); 191 | //显示的坐标位置不一样 192 | popWin.showAtLocation(excelView, Gravity.CENTER, 0, 500); 193 | } 194 | 195 | } 196 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/java/com/xt/excelview/lib/control/ExcelControlInter.java: -------------------------------------------------------------------------------- 1 | package com.xt.excelview.lib.control; 2 | 3 | import com.xt.excelview.lib.view.ExcelView; 4 | 5 | /** 6 | * 接口定义 7 | * 8 | * @author lxl 9 | */ 10 | public interface ExcelControlInter { 11 | 12 | /** 13 | * 绑定数据Model 14 | */ 15 | public void bindData(ExcelView.TableValueModel model); 16 | 17 | /** 18 | * 现实编辑键盘 19 | */ 20 | public void showKeyboard(ExcelView.TableValueModel tableModel, int[] selectRange, int selectType); 21 | 22 | } 23 | 24 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/java/com/xt/excelview/lib/dialog/ExcelEditDialog.java: -------------------------------------------------------------------------------- 1 | package com.xt.excelview.lib.dialog; 2 | 3 | import android.content.Context; 4 | import android.graphics.Color; 5 | import android.graphics.drawable.ColorDrawable; 6 | import android.util.TypedValue; 7 | import android.view.Gravity; 8 | import android.view.View; 9 | import android.widget.LinearLayout; 10 | import android.widget.PopupWindow; 11 | import android.widget.TextView; 12 | 13 | 14 | import com.xt.excelview.lib.R; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | /** 20 | * 通用dialog 21 | */ 22 | public class ExcelEditDialog extends PopupWindow implements View.OnClickListener { 23 | 24 | private LinearLayout mContainer; 25 | private ClickCallBack mCallBack; 26 | private int dipUnit = 3; 27 | 28 | 29 | public ExcelEditDialog(Context context, int w, int h) { 30 | super(context); 31 | setWidth(w); 32 | setHeight(h); 33 | initView(context); 34 | // setFocusable(true);//是否允许事件穿透 35 | setOutsideTouchable(true); 36 | setBackgroundDrawable(new ColorDrawable(0));//new ColorDrawable(0)即为透明背景 37 | } 38 | 39 | 40 | private void initView(Context context) { 41 | mContainer = new LinearLayout(context); 42 | mContainer.setOrientation(LinearLayout.HORIZONTAL); 43 | mContainer.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE); 44 | mContainer.setBackgroundColor(Color.BLACK); 45 | mContainer.setGravity(Gravity.CENTER_VERTICAL); 46 | int padding = dipUnit * 6; 47 | mContainer.setPadding(padding, padding, padding, padding); 48 | mContainer.setDividerDrawable(context.getResources().getDrawable(R.drawable.common_divider_ffffff)); 49 | setContentView(mContainer); 50 | } 51 | 52 | public void bindData(DialogModel dialogModel, ClickCallBack callBack) { 53 | mCallBack = callBack; 54 | mContainer.removeAllViews(); 55 | for (int i = 0; i < dialogModel.dataList.size(); i++) { 56 | TextView textView = new TextView(mContainer.getContext()); 57 | textView.setText(dialogModel.dataList.get(i)); 58 | textView.setOnClickListener(this); 59 | textView.setTag(i); 60 | textView.setTextColor(Color.WHITE); 61 | textView.setGravity(Gravity.CENTER); 62 | textView.setIncludeFontPadding(false); 63 | textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, dipUnit * 11); 64 | mContainer.addView(textView, createLP()); 65 | } 66 | } 67 | 68 | private LinearLayout.LayoutParams createLP() { 69 | LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); 70 | lp.weight = 1; 71 | lp.gravity = Gravity.CENTER_VERTICAL; 72 | //去掉text的 73 | // lp.topMargin = (int) mContainer.getContext().getResources().getDimension(R.dimen.dip_1); 74 | return lp; 75 | } 76 | 77 | @Override 78 | public void onClick(View v) { 79 | dismiss(); 80 | if (mCallBack == null) { 81 | return; 82 | } 83 | mCallBack.clickByIndex((int) v.getTag()); 84 | } 85 | 86 | public interface ClickCallBack { 87 | void clickByIndex(int index); 88 | } 89 | 90 | static public class DialogModel { 91 | List dataList = new ArrayList<>(); 92 | 93 | public void setDataList(List list) { 94 | dataList = list; 95 | } 96 | } 97 | 98 | public void setDipUnit(int dipUnit) { 99 | this.dipUnit = dipUnit; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/java/com/xt/excelview/lib/dialog/KeyBoardCenterDialog.java: -------------------------------------------------------------------------------- 1 | package com.xt.excelview.lib.dialog; 2 | 3 | import android.content.Context; 4 | import android.view.View; 5 | import android.view.ViewGroup; 6 | 7 | import com.xt.excelview.lib.R; 8 | 9 | 10 | /** 11 | * 编辑框2 12 | * 13 | * @author lxl 14 | */ 15 | public class KeyBoardCenterDialog extends KeyBoardDialog { 16 | 17 | public KeyBoardCenterDialog(Context context, int width, int height) { 18 | super(context, width, height); 19 | } 20 | 21 | 22 | protected void initView(Context context) { 23 | mContainer = (ViewGroup) View.inflate(context, R.layout.common_dialog_keyboard_center_layout, null); 24 | setContentView(mContainer); 25 | ViewGroup viewGroup = mContainer.findViewById(R.id.keyboard_center_container); 26 | for (int i = 0; i < viewGroup.getChildCount(); i++) { 27 | viewGroup.getChildAt(i).setOnClickListener(this); 28 | } 29 | } 30 | 31 | public void bindData(DialogModel dialogModel, SelectCallBack callBack) { 32 | mDialogModel = dialogModel; 33 | mCallBack = callBack; 34 | refreshViewSelect(""); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/java/com/xt/excelview/lib/dialog/KeyBoardDialog.java: -------------------------------------------------------------------------------- 1 | package com.xt.excelview.lib.dialog; 2 | 3 | import android.content.Context; 4 | import android.graphics.drawable.ColorDrawable; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.PopupWindow; 8 | import android.widget.TextView; 9 | 10 | import com.xt.excelview.lib.R; 11 | import com.xt.excelview.lib.util.StringUtil; 12 | 13 | 14 | /** 15 | * 编辑框1 16 | * 17 | * @author lxl 18 | */ 19 | public class KeyBoardDialog extends PopupWindow implements View.OnClickListener { 20 | 21 | public final static int TYPE_ADD = 1; 22 | public final static int TYPE_SUB = 2; 23 | public final static int TYPE_MULTI = 3; 24 | public final static int TYPE_DIVISION = 4; 25 | public final static int TYPE_ASSIGN = 5; 26 | 27 | protected ViewGroup mContainer; 28 | protected SelectCallBack mCallBack; 29 | protected DialogModel mDialogModel; 30 | 31 | public KeyBoardDialog(Context context, int width, int height) { 32 | super(context); 33 | setWidth(width); 34 | setHeight(height); 35 | initView(context); 36 | setFocusable(true);//是否允许事件穿透 37 | setOutsideTouchable(true); 38 | setBackgroundDrawable(new ColorDrawable(0));//new ColorDrawable(0)即为透明背景 39 | } 40 | 41 | 42 | protected void initView(Context context) { 43 | mContainer = (ViewGroup) View.inflate(context, R.layout.common_dialog_keyboard_layout, null); 44 | for (int i = 0; i < mContainer.getChildCount(); i++) { 45 | mContainer.getChildAt(i).setOnClickListener(this); 46 | } 47 | setContentView(mContainer); 48 | } 49 | 50 | public void bindData(DialogModel dialogModel, SelectCallBack callBack) { 51 | mDialogModel = dialogModel; 52 | mCallBack = callBack; 53 | refreshViewSelect(""); 54 | } 55 | 56 | public void refreshViewSelect(String typeValue) { 57 | int type = mDialogModel.type; 58 | mContainer.findViewById(R.id.keyboard_add).setSelected(type == TYPE_ADD); 59 | mContainer.findViewById(R.id.keyboard_sub).setSelected(type == TYPE_SUB); 60 | mContainer.findViewById(R.id.keyboard_multi).setSelected(type == TYPE_MULTI); 61 | mContainer.findViewById(R.id.keyboard_division).setSelected(type == TYPE_DIVISION); 62 | mContainer.findViewById(R.id.keyboard_assign).setSelected(type == TYPE_ASSIGN); 63 | if (StringUtil.emptyOrNull(typeValue)) { 64 | if (type == TYPE_ADD) { 65 | typeValue = "加"; 66 | } else if (type == TYPE_SUB) { 67 | typeValue = "减"; 68 | } else if (type == TYPE_MULTI) { 69 | typeValue = "乘"; 70 | } else if (type == TYPE_DIVISION) { 71 | typeValue = "除"; 72 | } else if (type == TYPE_ASSIGN) { 73 | typeValue = "编辑"; 74 | } 75 | } 76 | TextView typeValueText = (TextView) (mContainer.findViewById(R.id.keyboard_type_value)); 77 | if (typeValueText != null) { 78 | typeValueText.setText(typeValue); 79 | } 80 | } 81 | 82 | @Override 83 | public void onClick(View v) { 84 | int id = v.getId(); 85 | if (id == R.id.keyboard_close) { 86 | dismiss(); 87 | return; 88 | } 89 | TextView valueText = (TextView) (mContainer.findViewById(R.id.keyboard_value_value)); 90 | String typeValue = null; 91 | if (id == R.id.keyboard_add) { 92 | mDialogModel.type = TYPE_ADD; 93 | typeValue = "加"; 94 | } 95 | if (id == R.id.keyboard_sub) { 96 | mDialogModel.type = TYPE_SUB; 97 | typeValue = "减"; 98 | } 99 | if (id == R.id.keyboard_multi) { 100 | mDialogModel.type = TYPE_MULTI; 101 | typeValue = "乘"; 102 | } 103 | if (id == R.id.keyboard_division) { 104 | mDialogModel.type = TYPE_DIVISION; 105 | typeValue = "除"; 106 | } 107 | if (id == R.id.keyboard_assign) { 108 | mDialogModel.type = TYPE_ASSIGN; 109 | typeValue = "编辑"; 110 | } 111 | if (!StringUtil.emptyOrNull(typeValue)) { 112 | refreshViewSelect(typeValue); 113 | return; 114 | } 115 | if (id == R.id.keyboard_reversal && mCallBack != null) { 116 | mCallBack.selectByType(TYPE_MULTI, -1.0); 117 | dismiss(); 118 | return; 119 | } 120 | if (id == R.id.keyboard_action_confirm && mCallBack != null) { 121 | double v1 = Double.parseDouble(valueText.getText().toString()); 122 | mCallBack.selectByType(mDialogModel.type, v1); 123 | dismiss(); 124 | return; 125 | } 126 | 127 | String currentValue = valueText.getText().toString(); 128 | if (id == R.id.keyboard_num_1) { 129 | currentValue += "1"; 130 | } else if (id == R.id.keyboard_num_2) { 131 | currentValue += "2"; 132 | } else if (id == R.id.keyboard_num_3) { 133 | currentValue += "3"; 134 | } else if (id == R.id.keyboard_num_4) { 135 | currentValue += "4"; 136 | } else if (id == R.id.keyboard_num_5) { 137 | currentValue += "5"; 138 | } else if (id == R.id.keyboard_num_6) { 139 | currentValue += "6"; 140 | } else if (id == R.id.keyboard_num_7) { 141 | currentValue += "7"; 142 | } else if (id == R.id.keyboard_num_8) { 143 | currentValue += "8"; 144 | } else if (id == R.id.keyboard_num_9) { 145 | currentValue += "9"; 146 | } else if (id == R.id.keyboard_num_0) { 147 | currentValue += "0"; 148 | } else if (id == R.id.keyboard_del) { 149 | if (currentValue.length() >= 1) { 150 | currentValue = currentValue.substring(0, currentValue.length() - 1); 151 | } else { 152 | currentValue = ""; 153 | } 154 | } else if (id == R.id.keyboard_negative) { 155 | if (StringUtil.emptyOrNull(currentValue)) { 156 | currentValue = "-"; 157 | } else { 158 | currentValue = String.valueOf(Double.parseDouble(currentValue) * -1); 159 | } 160 | } else { 161 | return; 162 | } 163 | valueText.setText(currentValue); 164 | } 165 | 166 | public interface SelectCallBack { 167 | void selectByType(int type, double value); 168 | } 169 | 170 | static public class DialogModel { 171 | private int type = 0; 172 | 173 | public int getType() { 174 | return this.type; 175 | } 176 | 177 | public void setType(int type) { 178 | this.type = type; 179 | } 180 | } 181 | } 182 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/java/com/xt/excelview/lib/util/DeviceUtil.java: -------------------------------------------------------------------------------- 1 | package com.xt.excelview.lib.util; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.util.DisplayMetrics; 6 | import android.view.WindowManager; 7 | 8 | public class DeviceUtil { 9 | public static int getDisplayDensity(Activity context) { 10 | DisplayMetrics metric = new DisplayMetrics(); 11 | context.getWindowManager().getDefaultDisplay().getMetrics(metric); 12 | return metric.densityDpi; 13 | } 14 | 15 | /** 16 | * 获取屏幕尺寸 17 | */ 18 | public static int[] getScreenSize(Context context) { 19 | WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 20 | DisplayMetrics outMetrics = new DisplayMetrics(); 21 | wm.getDefaultDisplay().getMetrics(outMetrics); 22 | return new int[]{outMetrics.widthPixels, outMetrics.heightPixels}; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/java/com/xt/excelview/lib/util/ImageUtil.java: -------------------------------------------------------------------------------- 1 | package com.xt.excelview.lib.util; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.BitmapFactory; 6 | import android.graphics.Canvas; 7 | import android.graphics.PixelFormat; 8 | import android.graphics.drawable.BitmapDrawable; 9 | import android.graphics.drawable.Drawable; 10 | import android.os.Build; 11 | 12 | public class ImageUtil { 13 | 14 | public static Bitmap getBitmap(Context context, int drawableId) { 15 | Bitmap bitmap = null; 16 | if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { 17 | Drawable vectorDrawable = context.getDrawable(drawableId); 18 | bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(), 19 | vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); 20 | Canvas canvas = new Canvas(bitmap); 21 | vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); 22 | vectorDrawable.draw(canvas); 23 | } else { 24 | bitmap = BitmapFactory.decodeResource(context.getResources(), drawableId); 25 | } 26 | return bitmap; 27 | } 28 | 29 | public static Drawable zoomDrawable(Drawable drawable, int w, int h, int density) { 30 | int width = drawable.getIntrinsicWidth(); 31 | int height = drawable.getIntrinsicHeight(); 32 | Bitmap oldbmp = drawableToBitmap(drawable); 33 | Bitmap newbmp = Bitmap.createScaledBitmap(oldbmp, w, h, true); 34 | BitmapDrawable bitmapDrawable = new BitmapDrawable(null, newbmp); 35 | bitmapDrawable.setTargetDensity(density); 36 | int width1 = bitmapDrawable.getIntrinsicWidth(); 37 | int height2 = bitmapDrawable.getIntrinsicHeight(); 38 | return bitmapDrawable; 39 | } 40 | 41 | public static Bitmap drawableToBitmap(Drawable drawable) { 42 | int width = drawable.getIntrinsicWidth(); 43 | int height = drawable.getIntrinsicHeight(); 44 | Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 45 | : Bitmap.Config.RGB_565; 46 | Bitmap bitmap = Bitmap.createBitmap(width, height, config); 47 | Canvas canvas = new Canvas(bitmap); 48 | drawable.setBounds(0, 0, width, height); 49 | drawable.draw(canvas); 50 | return bitmap; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/java/com/xt/excelview/lib/util/StringUtil.java: -------------------------------------------------------------------------------- 1 | package com.xt.excelview.lib.util; 2 | 3 | public class StringUtil { 4 | public static boolean emptyOrNull(String str) { 5 | return str == null || str.length() <= 0; 6 | } 7 | 8 | 9 | } 10 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/java/com/xt/excelview/lib/view/CommonSeekBar.java: -------------------------------------------------------------------------------- 1 | package com.xt.excelview.lib.view; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.app.Activity; 5 | import android.content.Context; 6 | import android.content.res.TypedArray; 7 | import android.graphics.drawable.Drawable; 8 | import android.util.AttributeSet; 9 | import android.widget.SeekBar; 10 | 11 | import com.xt.excelview.lib.R; 12 | import com.xt.excelview.lib.util.DeviceUtil; 13 | import com.xt.excelview.lib.util.ImageUtil; 14 | 15 | /** 16 | * 滑动条 17 | * 18 | * @author lxl 19 | */ 20 | @SuppressLint("AppCompatCustomView") 21 | public class CommonSeekBar extends SeekBar { 22 | 23 | public CommonSeekBar(Context context, AttributeSet attrs) { 24 | this(context, attrs, 0); 25 | } 26 | 27 | public CommonSeekBar(Context context, AttributeSet attrs, int defStyleAttr) { 28 | super(context, attrs); 29 | //load styled attributes. 30 | final TypedArray attributes = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CommonSeekBar, 31 | defStyleAttr, 0); 32 | 33 | float height = attributes.getDimension(R.styleable.CommonSeekBar_seekbar_thumb_height, 24); 34 | float width = attributes.getDimension(R.styleable.CommonSeekBar_seekbar_thumb_width, 24); 35 | Drawable thumb = getThumb(); 36 | int displayDensity = DeviceUtil.getDisplayDensity((Activity) context); 37 | thumb = ImageUtil.zoomDrawable(thumb, (int) height, (int) width, displayDensity); 38 | attributes.recycle(); 39 | setThumb(thumb); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/java/com/xt/excelview/lib/view/CommonVerticalSeekBar.java: -------------------------------------------------------------------------------- 1 | package com.xt.excelview.lib.view; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.content.res.TypedArray; 6 | import android.graphics.Canvas; 7 | import android.util.AttributeSet; 8 | import android.util.Log; 9 | import android.view.MotionEvent; 10 | import android.view.ViewConfiguration; 11 | import android.view.ViewParent; 12 | 13 | import com.xt.excelview.lib.R; 14 | 15 | 16 | /** 17 | * 滑动条 18 | * 19 | * @author lxl 20 | */ 21 | @SuppressLint("AppCompatCustomView") 22 | public class CommonVerticalSeekBar extends CommonSeekBar { 23 | //true=正向,false=倒向 24 | private boolean isForward; 25 | private boolean mIsDragging; 26 | private float mTouchDownY; 27 | private int mScaledTouchSlop; 28 | private boolean isInScrollingContainer = false; 29 | 30 | public boolean isInScrollingContainer() { 31 | return isInScrollingContainer; 32 | } 33 | 34 | public void setInScrollingContainer(boolean isInScrollingContainer) { 35 | this.isInScrollingContainer = isInScrollingContainer; 36 | } 37 | 38 | /** 39 | * On touch, this offset plus the scaled value from the position of the 40 | * touch will form the progress value. Usually 0. 41 | */ 42 | float mTouchProgressOffset; 43 | 44 | public CommonVerticalSeekBar(Context context, AttributeSet attrs) { 45 | super(context, attrs); 46 | final TypedArray attributes = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CommonVerticalSeekBar, 47 | 0, 0); 48 | isForward = attributes.getBoolean(R.styleable.CommonVerticalSeekBar_seekbar_isforward, true); 49 | attributes.recycle(); 50 | } 51 | 52 | public CommonVerticalSeekBar(Context context, AttributeSet attrs, int defStyle) { 53 | super(context, attrs, defStyle); 54 | mScaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); 55 | final TypedArray attributes = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CommonVerticalSeekBar, 56 | defStyle, 0); 57 | isForward = attributes.getBoolean(R.styleable.CommonVerticalSeekBar_seekbar_isforward, true); 58 | } 59 | 60 | @Override 61 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 62 | super.onSizeChanged(h, w, oldh, oldw); 63 | } 64 | 65 | @Override 66 | public synchronized void setProgress(int progress) { 67 | super.setProgress(progress); 68 | onSizeChanged(getWidth(), getHeight(), 0, 0); 69 | } 70 | 71 | @Override 72 | protected synchronized void onMeasure(int widthMeasureSpec, 73 | int heightMeasureSpec) { 74 | super.onMeasure(heightMeasureSpec, widthMeasureSpec); 75 | setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth()); 76 | } 77 | 78 | @Override 79 | protected synchronized void onDraw(Canvas canvas) { 80 | int height = getHeight(); 81 | int width = getWidth(); 82 | Log.i("lxltest", "height:" + height + ",width:" + width); 83 | if (isForward) { 84 | canvas.rotate(90); 85 | canvas.translate(0, -20);//及时方向转换了,坐标轴原点还是之前的。 86 | } else { 87 | canvas.rotate(-90); 88 | canvas.translate(-getHeight(), 0); 89 | } 90 | super.onDraw(canvas); 91 | } 92 | 93 | @Override 94 | public boolean onTouchEvent(MotionEvent event) { 95 | if (!isEnabled()) { 96 | return false; 97 | } 98 | switch (event.getAction()) { 99 | case MotionEvent.ACTION_DOWN: 100 | if (isInScrollingContainer()) { 101 | mTouchDownY = event.getY(); 102 | } else { 103 | setPressed(true); 104 | invalidate(); 105 | onStartTrackingTouch(); 106 | trackTouchEvent(event); 107 | attemptClaimDrag(); 108 | onSizeChanged(getWidth(), getHeight(), 0, 0); 109 | } 110 | break; 111 | 112 | case MotionEvent.ACTION_MOVE: 113 | if (mIsDragging) { 114 | trackTouchEvent(event); 115 | 116 | } else { 117 | final float y = event.getY(); 118 | if (Math.abs(y - mTouchDownY) > mScaledTouchSlop) { 119 | setPressed(true); 120 | 121 | invalidate(); 122 | onStartTrackingTouch(); 123 | trackTouchEvent(event); 124 | attemptClaimDrag(); 125 | 126 | } 127 | } 128 | onSizeChanged(getWidth(), getHeight(), 0, 0); 129 | break; 130 | 131 | case MotionEvent.ACTION_UP: 132 | if (mIsDragging) { 133 | trackTouchEvent(event); 134 | onStopTrackingTouch(); 135 | setPressed(false); 136 | 137 | } else { 138 | // Touch up when we never crossed the touch slop threshold 139 | // should 140 | // be interpreted as a tap-seek to that location. 141 | onStartTrackingTouch(); 142 | trackTouchEvent(event); 143 | onStopTrackingTouch(); 144 | 145 | } 146 | onSizeChanged(getWidth(), getHeight(), 0, 0); 147 | // ProgressBar doesn't know to repaint the thumb drawable 148 | // in its inactive state when the touch stops (because the 149 | // value has not apparently changed) 150 | invalidate(); 151 | break; 152 | } 153 | return true; 154 | 155 | } 156 | 157 | private void trackTouchEvent(MotionEvent event) { 158 | float progress = 0; 159 | final int height = getHeight(); 160 | final int top = getPaddingTop(); 161 | final int bottom = getPaddingBottom(); 162 | final int available = height - top - bottom; 163 | int y = (int) event.getY(); 164 | float scale; 165 | if (isForward) { 166 | //正向 167 | if (y > height - bottom) { 168 | scale = 1.0f; 169 | } else if (y < top) { 170 | scale = 0.0f; 171 | } else { 172 | scale = (float) (y + top) / (float) available; 173 | progress = mTouchProgressOffset; 174 | } 175 | } else { 176 | //倒向 177 | // 下面是最小值 178 | if (y > height - bottom) { 179 | scale = 0.0f; 180 | } else if (y < top) { 181 | scale = 1.0f; 182 | } else { 183 | scale = (float) (available - y + top) / (float) available; 184 | progress = mTouchProgressOffset; 185 | } 186 | } 187 | final int max = getMax(); 188 | progress += scale * max; 189 | setProgress((int) progress); 190 | } 191 | 192 | /** 193 | * This is called when the user has started touching this widget. 194 | */ 195 | void onStartTrackingTouch() { 196 | mIsDragging = true; 197 | } 198 | 199 | /** 200 | * This is called when the user either releases his touch or the touch is 201 | * canceled. 202 | */ 203 | void onStopTrackingTouch() { 204 | mIsDragging = false; 205 | } 206 | 207 | private void attemptClaimDrag() { 208 | ViewParent p = getParent(); 209 | if (p != null) { 210 | p.requestDisallowInterceptTouchEvent(true); 211 | } 212 | } 213 | 214 | } 215 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/color/color_select_2072eb_33333.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/color/color_select_2870f6_666666.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/color/color_select_2870f6_999999.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/color/selector_blue_gray_textcolor.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/drawable/common_button_b3b8c1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/drawable/common_dialog_keyboard_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/ExcelViewLib/src/main/res/drawable/common_dialog_keyboard_close.png -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/drawable/common_divider_ffffff.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/drawable/common_execl_range_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/ExcelViewLib/src/main/res/drawable/common_execl_range_icon.png -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/drawable/common_keyboard_btn_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/drawable/common_keyboard_del2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/ExcelViewLib/src/main/res/drawable/common_keyboard_del2.png -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/drawable/common_keyboard_item_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/drawable/common_progress_drag_button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/ExcelViewLib/src/main/res/drawable/common_progress_drag_button.png -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/drawable/common_rect_0062ff_hollow.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/drawable/common_rect_c9ced4_hollow.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/drawable/common_rect_r2_2870f6_shadow.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/drawable/common_seekbar_style2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/drawable/original_common_corner_ffffff_r7.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/layout/common_dialog_keyboard_center_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 15 | 16 | 27 | 28 | 36 | 37 | 47 | 48 | 49 | 60 | 61 | 62 | 73 | 74 | 85 | 86 | 87 | 98 | 99 | 100 | 110 | 111 | 121 | 122 | 123 | 134 | 135 | 148 | 149 | 163 | 164 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/mipmap-hdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/ExcelViewLib/src/main/res/mipmap-hdpi/ic_launcher.webp -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/mipmap-hdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/ExcelViewLib/src/main/res/mipmap-hdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/ExcelViewLib/src/main/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/mipmap-mdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/ExcelViewLib/src/main/res/mipmap-mdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/mipmap-xhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/ExcelViewLib/src/main/res/mipmap-xhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/mipmap-xhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/ExcelViewLib/src/main/res/mipmap-xhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/mipmap-xxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/ExcelViewLib/src/main/res/mipmap-xxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/ExcelViewLib/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/mipmap-xxxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/ExcelViewLib/src/main/res/mipmap-xxxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/ExcelViewLib/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/values-land/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 48dp 3 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/values-w1240dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 200dp 3 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/values-w600dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 48dp 3 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/values/attr.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFBB86FC 4 | #FF6200EE 5 | #FF3700B3 6 | #FF03DAC5 7 | #FF018786 8 | #FF000000 9 | #FFFFFFFF 10 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 16dp 3 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ExcelView 3 | Settings 4 | 5 | First Fragment 6 | Second Fragment 7 | Next 8 | Previous 9 | 10 | Hello first fragment 11 | Hello second fragment. Arg: %1$s 12 | -------------------------------------------------------------------------------- /ExcelViewLib/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /PoiLib/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /PoiLib/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.library' 3 | } 4 | 5 | android { 6 | compileSdk 31 7 | 8 | defaultConfig { 9 | minSdk 26 10 | targetSdk 31 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | compileOptions { 22 | sourceCompatibility JavaVersion.VERSION_1_8 23 | targetCompatibility JavaVersion.VERSION_1_8 24 | } 25 | } 26 | 27 | dependencies { 28 | /** 29 | * poi 30 | */ 31 | api fileTree(dir: 'libs', include: ['*.jar']) 32 | compileOnly project(':ExcelViewLib') 33 | implementation 'stax:stax-api:1.0.1' 34 | } 35 | 36 | ext { 37 | PUBLISH_ARTIFACT_ID = 'excelview-poi' 38 | } 39 | apply from: 'publish.gradle' -------------------------------------------------------------------------------- /PoiLib/consumer-rules.pro: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/PoiLib/consumer-rules.pro -------------------------------------------------------------------------------- /PoiLib/libs/commons-collections4-4.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/PoiLib/libs/commons-collections4-4.4.jar -------------------------------------------------------------------------------- /PoiLib/libs/commons-compress-1.21.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/PoiLib/libs/commons-compress-1.21.jar -------------------------------------------------------------------------------- /PoiLib/libs/commons-io-2.11.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/PoiLib/libs/commons-io-2.11.0.jar -------------------------------------------------------------------------------- /PoiLib/libs/commons-math3-3.6.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/PoiLib/libs/commons-math3-3.6.1.jar -------------------------------------------------------------------------------- /PoiLib/libs/log4j-api-2.14.1(1).jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/PoiLib/libs/log4j-api-2.14.1(1).jar -------------------------------------------------------------------------------- /PoiLib/libs/poi-5.1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/PoiLib/libs/poi-5.1.0.jar -------------------------------------------------------------------------------- /PoiLib/libs/poi-ooxml-5.1.0(1).jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/PoiLib/libs/poi-ooxml-5.1.0(1).jar -------------------------------------------------------------------------------- /PoiLib/libs/poi-ooxml-full-5.1.0(1).jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/PoiLib/libs/poi-ooxml-full-5.1.0(1).jar -------------------------------------------------------------------------------- /PoiLib/libs/xmlbeans-5.0.2(1).jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/PoiLib/libs/xmlbeans-5.0.2(1).jar -------------------------------------------------------------------------------- /PoiLib/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /PoiLib/publish.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'maven-publish' 2 | apply plugin: 'signing' 3 | 4 | task androidSourcesJar(type: Jar) { 5 | classifier = 'sources' 6 | from android.sourceSets.main.java.source 7 | 8 | exclude "**/R.class" 9 | exclude "**/BuildConfig.class" 10 | } 11 | 12 | ext { 13 | PUBLISH_GROUP_ID = 'io.github.september26' 14 | PUBLISH_ARTIFACT_ID = 'excelview-poi' 15 | PUBLISH_VERSION = '0.9.4' 16 | } 17 | //ext { 18 | // PUBLISH_GROUP_ID = 'com.sunsta.livery' 19 | // PUBLISH_ARTIFACT_ID = 'livery' 20 | // PUBLISH_VERSION = '1.2.0' 21 | //} 22 | 23 | ext["signing.keyId"] = '' 24 | ext["signing.password"] = '' 25 | ext["signing.secretKeyRingFile"] = '' 26 | ext["ossrhUsername"] = '' 27 | ext["ossrhPassword"] = '' 28 | 29 | File secretPropsFile = project.rootProject.file('local.properties') 30 | if (secretPropsFile.exists()) { 31 | println "Found secret props file, loading props" 32 | Properties p = new Properties() 33 | p.load(new FileInputStream(secretPropsFile)) 34 | p.each { name, value -> 35 | ext[name] = value 36 | println ext[name] 37 | } 38 | } else { 39 | println "No props file, loading env vars" 40 | } 41 | publishing { 42 | publications { 43 | release(MavenPublication) { 44 | // The coordinates of the library, being set from variables that 45 | // we'll set up in a moment 46 | groupId PUBLISH_GROUP_ID 47 | artifactId PUBLISH_ARTIFACT_ID 48 | version PUBLISH_VERSION 49 | 50 | // Two artifacts, the `aar` and the sources 51 | artifact("$buildDir/outputs/aar/${project.getName()}-release.aar") 52 | artifact androidSourcesJar 53 | 54 | // Self-explanatory metadata for the most part 55 | pom { 56 | name = PUBLISH_ARTIFACT_ID 57 | description = 'excelView lib' 58 | // If your project has a dedicated site, use its URL here 59 | url = 'https://github.com/September26/ExcelView' 60 | licenses { 61 | license { 62 | //协议类型,一般默认Apache License2.0的话不用改: 63 | name = 'The Apache License, Version 2.0' 64 | url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' 65 | } 66 | } 67 | // configurations { 68 | // ignoredClassPatterns { 69 | // ignoredClassPattern = 'module-info' 70 | // } 71 | // } 72 | developers { 73 | developer { 74 | id = '5694209@qq.com' 75 | name = ossrhUsername 76 | email = '5694209@qq.com' 77 | } 78 | } 79 | // Version control info, if you're using GitHub, follow the format as seen here 80 | scm { 81 | //修改成你的Git地址: 82 | connection = 'scm:git:github.com/September26/ExcelView.git' 83 | developerConnection = 'scm:git:ssh://github.com/September26/ExcelView.git' 84 | //分支地址: 85 | url = 'https://github.com/September26/ExcelView' 86 | } 87 | // A slightly hacky fix so that your POM will include any transitive dependencies 88 | // that your library builds upon 89 | withXml { 90 | def dependenciesNode = asNode().appendNode('dependencies') 91 | 92 | project.configurations.implementation.allDependencies.each { 93 | if (it.name != 'unspecified') { 94 | def dependencyNode = dependenciesNode.appendNode('dependency') 95 | dependencyNode.appendNode('groupId', it.group) 96 | dependencyNode.appendNode('artifactId', it.name) 97 | dependencyNode.appendNode('version', it.version) 98 | } 99 | } 100 | } 101 | } 102 | } 103 | } 104 | repositories { 105 | // The repository to publish to, Sonatype/MavenCentral 106 | maven { 107 | // This is an arbitrary name, you may also use "mavencentral" or 108 | // any other name that's descriptive for you 109 | name = "mavenCentral" 110 | 111 | def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" 112 | def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/" 113 | // You only need this if you want to publish snapshots, otherwise just set the URL 114 | // to the release repo directly 115 | url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl 116 | 117 | // The username and password we've fetched earlier 118 | credentials { 119 | username ossrhUsername 120 | password ossrhPassword 121 | } 122 | } 123 | } 124 | } 125 | signing { 126 | sign publishing.publications 127 | } -------------------------------------------------------------------------------- /PoiLib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /PoiLib/src/main/java/com/xt/excelview/poi/poi/PoiUtil.java: -------------------------------------------------------------------------------- 1 | package com.xt.excelview.poi.poi; 2 | 3 | import com.xt.excelview.lib.view.ExcelView; 4 | 5 | import org.apache.poi.hssf.usermodel.HSSFSheet; 6 | import org.apache.poi.hssf.usermodel.HSSFWorkbook; 7 | import org.apache.poi.ss.usermodel.Cell; 8 | import org.apache.poi.ss.usermodel.CellType; 9 | import org.apache.poi.ss.usermodel.Row; 10 | import org.apache.poi.ss.usermodel.Sheet; 11 | import org.apache.poi.ss.usermodel.Workbook; 12 | import org.apache.poi.ss.usermodel.WorkbookFactory; 13 | 14 | import java.io.File; 15 | import java.io.FileInputStream; 16 | import java.io.FileOutputStream; 17 | import java.io.InputStream; 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | /** 22 | * 提供导入和导出功能 23 | * 24 | * @author lxl 25 | */ 26 | public class PoiUtil { 27 | 28 | public static ExcelView.TableValueModel readExcel(File file) { 29 | ExcelView.TableValueModel model = new ExcelView.TableValueModel(); 30 | if (!file.exists()) { 31 | return model; 32 | } 33 | InputStream fis; 34 | List> dataList = model.dataList; 35 | try { 36 | fis = new FileInputStream(file); 37 | Workbook wk; 38 | if (file.getName().endsWith("xls")) { 39 | wk = new HSSFWorkbook(fis); 40 | } else { 41 | wk = WorkbookFactory.create(fis); 42 | } 43 | //获取第一张Sheet表 44 | Sheet sheet = wk.getSheetAt(0); 45 | for (Row r : sheet) { 46 | ArrayList line = new ArrayList<>(); 47 | for (int i = r.getFirstCellNum(); i < r.getLastCellNum(); i++) { 48 | Cell cell = r.getCell(i); 49 | if (cell.getCellType() == CellType.NUMERIC) { 50 | line.add(cell.getNumericCellValue()); 51 | } else if (cell.getCellType() == CellType.STRING) { 52 | line.add(Double.parseDouble(cell.getStringCellValue())); 53 | } 54 | } 55 | dataList.add(line); 56 | } 57 | } catch (Exception e) { 58 | e.printStackTrace(); 59 | } 60 | // model.rows = dataList.size(); 61 | // model.columns = dataList.get(0).size(); 62 | return model; 63 | } 64 | 65 | public static String write2Excel(String filePath, ExcelView.TableValueModel model) { 66 | // 判断后缀名,后缀名不同,生成的流不同 67 | if (filePath.endsWith("xlsx")) { 68 | poiwriteXlsx(model, filePath); 69 | return "不支持的文件格式"; 70 | } else { 71 | return poiWriteXls(model, filePath); 72 | } 73 | 74 | } 75 | 76 | // SSF对应的是xls格式 77 | private static String poiWriteXls(ExcelView.TableValueModel model, String filepath) { 78 | InputStream inp; 79 | ifexist(filepath); 80 | try { 81 | List> dataList = model.dataList; 82 | inp = new FileInputStream(filepath); 83 | int rownum = dataList.size(); 84 | int columnum = dataList.get(0).size(); 85 | 86 | HSSFWorkbook wb = new HSSFWorkbook(); 87 | HSSFSheet sheet = wb.createSheet("sheet1"); 88 | for (int i = 0; i < rownum; i++) { 89 | // System.out.println("i:"+i); 90 | Row row = sheet.createRow(i); 91 | for (int j = 0; j < columnum; j++) { 92 | /* System.out.println("j:"+j); */ 93 | Cell cell = row.createCell(j); 94 | // 设置格式 95 | cell.setCellType(CellType.NUMERIC); 96 | // 设置值 97 | cell.setCellValue(dataList.get(i).get(j)); 98 | } 99 | } 100 | // Write the output to a file 101 | FileOutputStream fileOut = new FileOutputStream(filepath); 102 | wb.write(fileOut); 103 | fileOut.close(); 104 | inp.close(); 105 | } catch (Exception e) { 106 | e.printStackTrace(); 107 | StringBuilder builder = new StringBuilder(); 108 | StackTraceElement[] stackTrace = e.getStackTrace(); 109 | for (StackTraceElement element : stackTrace) { 110 | builder.append(element.toString() + "\n"); 111 | } 112 | return builder.toString(); 113 | } 114 | return "success"; 115 | } 116 | 117 | // XSSF对应的是xlsx格式 118 | private static void poiwriteXlsx(ExcelView.TableValueModel model, String filepath) { 119 | InputStream inp; 120 | ifexist(filepath); 121 | try { 122 | inp = new FileInputStream(filepath); 123 | int rownum = model.dataList.size(); 124 | int columnum = model.dataList.get(0).size(); 125 | Workbook wb = WorkbookFactory.create(inp); 126 | Sheet sheet = wb.createSheet("sheet1"); 127 | for (int i = 0; i < rownum; i++) { 128 | // System.out.println("i:"+i); 129 | Row row = sheet.createRow(i); 130 | for (int j = 0; j < columnum; j++) { 131 | /* System.out.println("j:"+j); */ 132 | Cell cell = row.createCell(j); 133 | // 设置格式 134 | cell.setCellType(CellType.STRING); 135 | // 设置值 136 | cell.setCellValue(model.dataList.get(i).get(j)); 137 | } 138 | } 139 | // Write the output to a file 140 | FileOutputStream fileOut = new FileOutputStream(filepath); 141 | wb.write(fileOut); 142 | fileOut.close(); 143 | inp.close(); 144 | System.out.println("写入完成"); 145 | } catch (Exception e) { 146 | // TODO Auto-generated catch block 147 | e.printStackTrace(); 148 | } 149 | } 150 | 151 | // 传入文件的地址,判断文件是否存在,如果不存在的话创建该文件 152 | // 这个功能好像还存在一个小BUG,直接createNewFile();的文件不能用,以后找方法解决。 153 | public static void ifexist(String path) { 154 | try { 155 | File file = new File(path); 156 | if (!file.exists()) { 157 | System.out.println("文件不存在,创建该文件,文件地址为:" + path); 158 | file.createNewFile(); 159 | } 160 | } catch (Exception e) { 161 | // TODO Auto-generated catch block 162 | e.printStackTrace(); 163 | } 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /PoiLib/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /PoiLib/src/main/res/drawable/common_button_b3b8c1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /PoiLib/src/main/res/drawable/common_dialog_keyboard_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/PoiLib/src/main/res/drawable/common_dialog_keyboard_close.png -------------------------------------------------------------------------------- /PoiLib/src/main/res/drawable/common_divider_ffffff.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /PoiLib/src/main/res/drawable/common_execl_range_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/PoiLib/src/main/res/drawable/common_execl_range_icon.png -------------------------------------------------------------------------------- /PoiLib/src/main/res/drawable/common_keyboard_btn_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /PoiLib/src/main/res/drawable/common_keyboard_del2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/PoiLib/src/main/res/drawable/common_keyboard_del2.png -------------------------------------------------------------------------------- /PoiLib/src/main/res/drawable/common_keyboard_item_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /PoiLib/src/main/res/drawable/common_progress_drag_button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/PoiLib/src/main/res/drawable/common_progress_drag_button.png -------------------------------------------------------------------------------- /PoiLib/src/main/res/drawable/common_rect_0062ff_hollow.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /PoiLib/src/main/res/drawable/common_rect_c9ced4_hollow.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /PoiLib/src/main/res/drawable/common_rect_r2_2870f6_shadow.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /PoiLib/src/main/res/drawable/common_seekbar_style2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /PoiLib/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /PoiLib/src/main/res/drawable/original_common_corner_ffffff_r7.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /PoiLib/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 16dp 3 | -------------------------------------------------------------------------------- /PoiLib/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ExcelView-POI 3 | 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ExcelView 2 | 3 | ## 项目介绍 4 | 项目是仿照WPS中Excel的功能实现的,实现了显示,滑动,编辑等基本功能,并且结构简单,可扩展性强,绘制性能较高。 5 | 项目分为两个支持库: 6 | ### ExcelViewLib: 7 | 实现高性能表格控件的绘制,并支持各种交互方式的输入,可扩展性高。 8 | 使用方式:implementation 'io.github.september26:excelview:0.9.4' 9 | 10 | ### PoiLib: 11 | 打包POI的所有需要的所有jar包,并针对安卓进行针对性适配改动,实现了安卓设备上读写excel的功能。如果只有安卓上使用POI需求的同学,只依赖这个库即可。 12 | 使用方式:implementation 'io.github.september26:excelview-poi:0.9.4' 13 | 14 | 项目还有一些excel的功能未实现,比如公式计算,自动扩展等等,希望后续使用的人能够一起参与进来,逐渐的进行完善和扩展。 15 | 同步CSDN介绍:https://blog.csdn.net/rzleilei/article/details/121016009 16 | 17 | ## 效果简介 18 | **整体效果图** 19 | ![整体效果图](pics/img/desc.png) 20 | 21 | **拖动效果图** 22 | ![拖动效果图](pics/img/drag.gif) 23 | 24 | **范围选择效果图** 25 | ![范围选择效果图](pics/img/rangselect.gif) 26 | 27 | **非编辑区域选择效果图** 28 | ![非编辑区域效果图](pics/img/unrangselect.gif) 29 | 30 | **编辑效果图** 31 | ![编辑效果图](pics/img/edit.gif) 32 | 33 | ## 核心元素介绍 34 | 采用组合的设计模式,主要对象有以下几个, 35 | * ExcelView:负责数据以及各种状态的渲染。 36 | * ExcelEditDialog:选中某个cell后弹出复制,粘贴,加减乘除等选择框。 37 | * KeyBoardDialog:负责对选中数据的编辑操作。 38 | * ExcelControl:逻辑处理器。负责以上三个对象之间的关系关联。后续的导出xls功能,也通过由其负责串联。 39 | * CommonSeekBar,CommonVerticalSeekBar:横向纵向的滚动条。 40 | 41 | 42 | ## 使用介绍 43 | * 1.参照sample中的使用方法,build.gradle中添加依赖库:'io.github.september26:excelview:0.9.4' 44 | * 2.参照app中Fragment1和Fragment2中的使用方法,直接使用ExcelControlImpl中已经写好的组合逻辑,或者继承ExcelControlImpl重写其组合逻辑。 45 | * 3.可扩展性:可通过继承ControlImpl重写其方法实现不同的业务场景逻辑。 46 | * 4.可扩展性:可自定义Dialog,通过ControlImpl和ExcelView组合实现对应场景逻辑。 47 | * 5.如果需要安卓上读写excel的能力,请添加依赖库'io.github.september26:excelview-poi:0.9.4'。使用PoiUtil进行读写操作。 48 | 49 | ## 后续计划 50 | * 1.添加excel导出为xls文件功能。(PS :0.9.4的版本已完成。2022.2.9) 51 | * 2.拆分页面绘制和excel文件读写为两个支持库。(PS :0.9.4的版本已完成。2022.2.9) 52 | * 3.看issues中的需求。 53 | 54 | 55 | ## 实现逻辑介绍 56 | WPS中excel实现了相当多的功能,不可能完全都实现,所以本项目聚焦于其核心功能实现即可。 57 | 核心功能总结下来就是读,写,存这三点,围绕这三点,我们整理下我们要实现的需求点: 58 | * 1.在一屏幕的范围内显示几十甚至上百个Cell,并且不能卡顿。 59 | * 2.一屏显示不下时,可以横向,纵向,斜向拖动表格,并且滑动流畅。 60 | * 3.横向,纵向标题的实现。 61 | * 4.可以进行单元格的选中。 62 | * 5.可以通过拖动的方式实现批量的选择。 63 | * 6.不可编辑区域的实现。 64 | * 7.可以针对选中的单元格进行数据上的修改操作。 65 | * 8.显示弹出框,支持对数据进行修。 66 | * 9.修改的数据进行变色显示。 67 | * 10.横向,纵向标题的实现。 68 | * 11.编辑好的数据,可以导出到xls和xlsx文件当中. 69 | 70 | 围绕这11个需求点,我们挨个去讨论下如何去实现。 71 | * **1.在一屏幕的范围内显示几十甚至上百个Cell,并且不能卡顿。** 72 |

大批量的显示数据,第一个想到的肯定是RecyclerView搭配GridLayout,但是实际上简单试了下,由于RecyclerView的原理仍然是每个Cell都需要单独创建,所以效率是很低的,采用RecyclerView的 73 | 方案会导致首次进入相当的卡顿,所以这个方案弃用。想要高效率的绘制,我们首先要了解下整个View的渲染流程,这里就不详细展开了,我们实现的核心就是用一个View去实现所有的功能,抛出掉measure和layout 方法,只重写draw方法。因为View的数量多少对draw方法影响是很小的。所以最终决定采用Canvas自绘的方式,所以的内容,分割线的位置都一次性计算好,然后通过canvas进行绘制。 74 |

75 | * **2.一屏显示不下时,可以横向,纵向,斜向拖动表格,并且滑动流畅。** 76 |

假设我们横向有10个cell,但是横向一屏只能显示5个cell,那我们想显示4到9的cell时怎么办呢?这里我想了一个简单的实现方案,还是按照10个去计算,显示4到9的时候,只要每个cell的x值都减去4个cell的 宽度即可。这样第0到4个cell,会因为x轴计算为负数而被挤出屏幕,也就不会在屏幕内显示了。高度的实现原理也是一样的。 77 |

滑动自然采用的是重写dispatchTouchEvent方法计算横向纵向偏移的方式。

78 | 79 | * **3.横向,纵向标题的实现。** 80 |

横向标题和纵向标题,这个需要逻辑特殊处理下。横向标题的话,一样计算一个偏移量,然后每个cell的Y坐标都在基础之上增加这个偏移量。纵向原理类似。

81 | 82 | 83 | * **4.可以进行单元格的选中。** 84 |

单元格选中是下面这种样式的,实现不难,因为单元格是挨个计算的,所以计算到这个单元格的时候,额外添加样式即可。

85 |

但是因为绘制选中单元格肯定会影响四周的单元格,所以我这里进行了两遍绘制,先绘制所有单元格,然后再去绘制选中单元格,选中单元格的样式是直接覆盖上去的。

86 | 87 | * **5.可以通过拖动的方式实现批量的选择。** 88 |

拖动选择和拖动表格都用到了手势监听,所以肯定会有冲突。我这里的解决方案就是看是否先选中,如果选中了某个cell则认为是拖动选择,否则认为是拖动表格。

89 | 90 | * **6.不可编辑区域的实现。** 91 |

手势滑动,滑动结束后计算坐标,如果在不可编辑区域,则把选中的范围做适当的修改。

92 | 93 | * **7.可以针对选中的单元格进行数据上的修改操作。** 94 |

个人很欣赏RcyclerView的组合模式,所以这里我也使用了组合的设计模式。ExcelView本身只注重数据的渲染和选择,修改,变色等等所有的逻辑都交给外部类来控制。

95 | 96 | * **8.显示弹出框,支持对数据进行修改。** 97 |

组合模式分为三块,弹出框Dialog, ExcelView,组合器Control。编辑的弹出框并不直接和ExcelView绑定,而是通过Control来实现一个双向的绑定。

98 |

这样ExcelView可以适配不同的Dialog,同样的Dialog也可以适配不同的ExcelView。

99 | 100 | * **9.修改的数据进行变色显示。** 101 |

ExcelView提供一个功能,设置范围的颜色,由外部来调用。这样不仅仅修改后可以进行变色,用户完全可以根据特定场景,根据自己的选择来使用。

102 | 103 | * **0.横向纵向拖动条的显示。** 104 |

这个实现难点在于纵向的滑动条。借鉴网上的方案进行了实现。也放到项目里面供选择使用。

105 | 106 | * **11.编辑好的数据,可以导出到xls和xlsx文件当中。** 107 |

xls格式已经实现,xlsx格式也已经实现

108 | 109 | ## 更新记录; 110 | 2021.11.30:支持xlsx格式的读取和写入 111 | 2021.11.01:发布到mavenCenter仓库 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | } 4 | 5 | android { 6 | compileSdk 31 7 | 8 | defaultConfig { 9 | applicationId "com.xt.excelview.demo" 10 | minSdk 26 11 | targetSdk 31 12 | versionCode 1 13 | versionName "1.0" 14 | 15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 16 | } 17 | 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | compileOptions { 25 | sourceCompatibility JavaVersion.VERSION_1_8 26 | targetCompatibility JavaVersion.VERSION_1_8 27 | } 28 | buildFeatures { 29 | viewBinding true 30 | } 31 | } 32 | 33 | dependencies { 34 | 35 | implementation 'androidx.appcompat:appcompat:1.2.0' 36 | implementation 'com.google.android.material:material:1.3.0' 37 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4' 38 | implementation 'androidx.navigation:navigation-fragment:2.3.5' 39 | implementation 'androidx.navigation:navigation-ui:2.3.5' 40 | // testImplementation 'junit:junit:4.+' 41 | // androidTestImplementation 'androidx.test.ext:junit:1.1.2' 42 | // androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 43 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.0" 44 | implementation project(':ExcelViewLib') 45 | implementation project(':PoiLib') 46 | } -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 18 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /app/src/main/assets/demo.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/app/src/main/assets/demo.xls -------------------------------------------------------------------------------- /app/src/main/assets/demo.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/September26/ExcelView/522a6fedc174d6eebbcd3d28640702ca11272005/app/src/main/assets/demo.xlsx -------------------------------------------------------------------------------- /app/src/main/java/com/xt/excelview/Fragment1.java: -------------------------------------------------------------------------------- 1 | package com.xt.excelview; 2 | 3 | import android.os.Bundle; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | 8 | import androidx.annotation.NonNull; 9 | import androidx.annotation.Nullable; 10 | import androidx.fragment.app.Fragment; 11 | 12 | import com.xt.excelview.databinding.FragmentFirstBinding; 13 | import com.xt.excelview.lib.control.ExcelControlInter; 14 | import com.xt.excelview.lib.control.ExcelControlImpl; 15 | import com.xt.excelview.lib.view.ExcelView; 16 | 17 | import java.math.BigDecimal; 18 | import java.util.ArrayList; 19 | 20 | /** 21 | * demo1样例 22 | * 直接使用ExcelControlImpl以及其中的逻辑 23 | * 24 | * @author lxl 25 | */ 26 | public class Fragment1 extends Fragment { 27 | 28 | private FragmentFirstBinding binding; 29 | 30 | @Override 31 | public View onCreateView( 32 | LayoutInflater inflater, ViewGroup container, 33 | Bundle savedInstanceState 34 | ) { 35 | 36 | binding = FragmentFirstBinding.inflate(inflater, container, false); 37 | return binding.getRoot(); 38 | } 39 | 40 | @Override 41 | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { 42 | super.onViewCreated(view, savedInstanceState); 43 | ExcelControlInter control = new ExcelControlImpl(binding.excelView, binding.scrollX, binding.scrollY, null); 44 | ExcelView.TableValueModel tableValueModel = getModel(); 45 | //进行绑定 46 | control.bindData(tableValueModel); 47 | } 48 | 49 | @Override 50 | public void onDestroyView() { 51 | super.onDestroyView(); 52 | binding = null; 53 | } 54 | 55 | public ExcelView.TableValueModel getModel() { 56 | ExcelView.TableValueModel model = new ExcelView.TableValueModel(); 57 | model.columnTitle = "纵向标题"; 58 | model.rowTitle = "横向标题"; 59 | model.onlyReadXNum = 2; 60 | model.onlyReadYNum = 1; 61 | 62 | //横向,纵向都设置为30格 63 | int size = 30; 64 | for (int i = 1; i < size; i++) { 65 | ArrayList strings = new ArrayList<>(); 66 | for (int j = 1; j < size; j++) { 67 | strings.add(new BigDecimal(i + (double) j / 100.0).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue()); 68 | } 69 | model.dataList.add(strings); 70 | } 71 | model.rows = model.dataList.size(); 72 | model.columns = model.dataList.get(0).size(); 73 | return model; 74 | } 75 | 76 | } -------------------------------------------------------------------------------- /app/src/main/java/com/xt/excelview/Fragment2.java: -------------------------------------------------------------------------------- 1 | package com.xt.excelview; 2 | 3 | import android.os.Bundle; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | 8 | import androidx.annotation.NonNull; 9 | import androidx.fragment.app.Fragment; 10 | 11 | import com.xt.excelview.custom.CustomControlImpl; 12 | import com.xt.excelview.databinding.FragmentSecondBinding; 13 | import com.xt.excelview.lib.control.ExcelControlInter; 14 | import com.xt.excelview.lib.view.ExcelView; 15 | 16 | import java.math.BigDecimal; 17 | import java.util.ArrayList; 18 | 19 | public class Fragment2 extends Fragment { 20 | 21 | private FragmentSecondBinding binding; 22 | 23 | @Override 24 | public View onCreateView( 25 | LayoutInflater inflater, ViewGroup container, 26 | Bundle savedInstanceState 27 | ) { 28 | binding = FragmentSecondBinding.inflate(inflater, container, false); 29 | return binding.getRoot(); 30 | } 31 | 32 | public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { 33 | super.onViewCreated(view, savedInstanceState); 34 | ExcelControlInter control = new CustomControlImpl(binding.excelView, null); 35 | ExcelView.TableValueModel tableValueModel = getModel(); 36 | //进行绑定 37 | control.bindData(tableValueModel); 38 | } 39 | 40 | @Override 41 | public void onDestroyView() { 42 | super.onDestroyView(); 43 | binding = null; 44 | } 45 | 46 | public ExcelView.TableValueModel getModel() { 47 | ExcelView.TableValueModel model = new ExcelView.TableValueModel(); 48 | model.columnTitle = "纵向标题"; 49 | model.rowTitle = "横向标题"; 50 | model.onlyReadXNum = 2; 51 | model.onlyReadYNum = 1; 52 | 53 | //横向,纵向都设置为30格 54 | int size = 30; 55 | for (int i = 1; i < size; i++) { 56 | ArrayList strings = new ArrayList<>(); 57 | for (int j = 1; j < size; j++) { 58 | strings.add(new BigDecimal(i + (double) j / 100.0).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue()); 59 | } 60 | model.dataList.add(strings); 61 | } 62 | model.rows = model.dataList.size(); 63 | model.columns = model.dataList.get(0).size(); 64 | return model; 65 | } 66 | } -------------------------------------------------------------------------------- /app/src/main/java/com/xt/excelview/Fragment3.java: -------------------------------------------------------------------------------- 1 | package com.xt.excelview; 2 | 3 | import android.os.Bundle; 4 | import android.util.Log; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | 9 | import androidx.annotation.NonNull; 10 | import androidx.annotation.Nullable; 11 | import androidx.fragment.app.Fragment; 12 | 13 | import com.xt.excelview.custom.CustomControlImpl; 14 | import com.xt.excelview.databinding.FragmentThirdBinding; 15 | import com.xt.excelview.util.IOHelper; 16 | import com.xt.excelview.lib.control.ExcelControlInter; 17 | import com.xt.excelview.lib.view.ExcelView; 18 | import com.xt.excelview.poi.poi.PoiUtil; 19 | 20 | import java.io.File; 21 | import java.io.IOException; 22 | import java.io.InputStream; 23 | 24 | public class Fragment3 extends Fragment { 25 | 26 | private FragmentThirdBinding binding; 27 | private final String FILE_NAME = "demo"; 28 | private String FILE_PATH; 29 | 30 | @Override 31 | public void onCreate(@Nullable Bundle savedInstanceState) { 32 | super.onCreate(savedInstanceState); 33 | FILE_PATH = getActivity().getFilesDir().getAbsolutePath() + File.separator; 34 | } 35 | 36 | @Override 37 | public View onCreateView( 38 | LayoutInflater inflater, ViewGroup container, 39 | Bundle savedInstanceState 40 | ) { 41 | binding = FragmentThirdBinding.inflate(inflater, container, false); 42 | return binding.getRoot(); 43 | } 44 | 45 | public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { 46 | super.onViewCreated(view, savedInstanceState); 47 | //拷贝文件到data/file目录下,然后跳转 48 | Bundle arguments = getArguments(); 49 | String type = "xls"; 50 | if (arguments != null) { 51 | type = arguments.getString("type"); 52 | } 53 | String fileName = FILE_NAME + "." + type; 54 | String filePath = FILE_PATH + fileName; 55 | File file = new File(filePath); 56 | if (!file.exists()) { 57 | try { 58 | InputStream open = getActivity().getAssets().open(fileName); 59 | IOHelper.copyFileFromInputStream(open, file); 60 | } catch (IOException e) { 61 | e.printStackTrace(); 62 | } 63 | } 64 | showExcel(file, filePath); 65 | } 66 | 67 | private void showExcel(File file, String filePath) { 68 | ExcelControlInter control = new CustomControlImpl(binding.excelView, null); 69 | ExcelView.TableValueModel model = PoiUtil.readExcel(file); 70 | Log.i("lxltest", "model:" + model.dataList.size()); 71 | //进行绑定 72 | control.bindData(model); 73 | 74 | binding.buttonSave.setOnClickListener(v -> { 75 | //很对model生成 76 | PoiUtil.write2Excel(filePath, model); 77 | }); 78 | } 79 | 80 | @Override 81 | public void onDestroyView() { 82 | super.onDestroyView(); 83 | binding = null; 84 | } 85 | 86 | } -------------------------------------------------------------------------------- /app/src/main/java/com/xt/excelview/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.xt.excelview; 2 | 3 | import android.os.Bundle; 4 | 5 | import androidx.appcompat.app.AppCompatActivity; 6 | import androidx.fragment.app.Fragment; 7 | import androidx.fragment.app.FragmentTransaction; 8 | 9 | import com.xt.excelview.databinding.ActivityMainBinding; 10 | 11 | 12 | public class MainActivity extends AppCompatActivity { 13 | 14 | private ActivityMainBinding binding; 15 | private Fragment1 firstFragment; 16 | private Fragment2 secondFragment; 17 | private Fragment3 thirdFragment; 18 | private int REQUEST_CODE = 1; 19 | 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | binding = ActivityMainBinding.inflate(getLayoutInflater()); 24 | setContentView(binding.getRoot()); 25 | 26 | 27 | binding.buttonFirst.setOnClickListener(v -> { 28 | if (firstFragment == null) { 29 | firstFragment = new Fragment1(); 30 | } 31 | showFragment(firstFragment); 32 | }); 33 | 34 | binding.buttonSecond.setOnClickListener(v -> { 35 | if (secondFragment == null) { 36 | secondFragment = new Fragment2(); 37 | } 38 | showFragment(secondFragment); 39 | }); 40 | 41 | binding.buttonThird.setOnClickListener(v -> { 42 | if (thirdFragment == null) { 43 | thirdFragment = new Fragment3(); 44 | } 45 | Bundle bundle = new Bundle(); 46 | bundle.putString("type", "xls"); 47 | thirdFragment.setArguments(bundle); 48 | showFragment(thirdFragment); 49 | }); 50 | 51 | binding.buttonFourth.setOnClickListener(v -> { 52 | if (thirdFragment == null) { 53 | thirdFragment = new Fragment3(); 54 | } 55 | Bundle bundle = new Bundle(); 56 | bundle.putString("type", "xlsx"); 57 | thirdFragment.setArguments(bundle); 58 | showFragment(thirdFragment); 59 | }); 60 | } 61 | 62 | private void showFragment(Fragment fragment) { 63 | FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); 64 | if (!fragment.isAdded()) { 65 | fragmentTransaction.add(android.R.id.content, fragment); 66 | fragmentTransaction.addToBackStack(null); 67 | fragmentTransaction.commit(); 68 | } else { 69 | fragmentTransaction.show(fragment); 70 | } 71 | } 72 | 73 | // private void requestPermission(Context context) { 74 | // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { 75 | // // 先判断有没有权限 76 | // if (Environment.isExternalStorageManager()) { 77 | // readFile(); 78 | // } else { 79 | // Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION); 80 | // intent.setData(Uri.parse("package:" + context.getPackageName())); 81 | // startActivityForResult(intent, REQUEST_CODE); 82 | // } 83 | // } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 84 | // // 先判断有没有权限 85 | // if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED && 86 | // ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { 87 | // readFile(); 88 | // } else { 89 | // ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE); 90 | // } 91 | // } else { 92 | // readFile(); 93 | // } 94 | // } 95 | // 96 | // public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 97 | // super.onRequestPermissionsResult(requestCode, permissions, grantResults); 98 | // if (requestCode == REQUEST_CODE) { 99 | // if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED && 100 | // ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { 101 | // readFile(); 102 | // } else { 103 | // Toast.makeText(this, "存储权限获取失败", Toast.LENGTH_LONG).show(); 104 | // } 105 | // } 106 | // } 107 | // 108 | // protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { 109 | // super.onActivityResult(requestCode, resultCode, data); 110 | // if (requestCode == REQUEST_CODE && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { 111 | // if (Environment.isExternalStorageManager()) { 112 | // readFile(); 113 | // } else { 114 | // Toast.makeText(this, "存储权限获取失败", Toast.LENGTH_LONG).show(); 115 | // } 116 | // } 117 | // } 118 | } -------------------------------------------------------------------------------- /app/src/main/java/com/xt/excelview/custom/CustomControlImpl.java: -------------------------------------------------------------------------------- 1 | package com.xt.excelview.custom; 2 | 3 | import android.graphics.Color; 4 | import android.view.Gravity; 5 | import android.view.View; 6 | import android.widget.Toast; 7 | 8 | import com.xt.excelview.lib.control.ExcelControlImpl; 9 | import com.xt.excelview.lib.dialog.KeyBoardCenterDialog; 10 | import com.xt.excelview.lib.dialog.KeyBoardDialog; 11 | import com.xt.excelview.lib.util.DeviceUtil; 12 | import com.xt.excelview.lib.view.ExcelView; 13 | 14 | import java.util.List; 15 | 16 | /** 17 | * 开发者自定义 18 | */ 19 | public class CustomControlImpl extends ExcelControlImpl { 20 | 21 | public CustomControlImpl(ExcelView excelView, View.OnClickListener listener) { 22 | super(excelView, listener); 23 | } 24 | 25 | @Override 26 | public void showKeyboard(ExcelView.TableValueModel tableModel, int[] selectRange, int selectType) { 27 | //这里使用KeyBoardCenterDialog替换原来的KeyBoardDialog,从而实现不一样的显示效果 28 | List> dataList = tableModel.dataList; 29 | KeyBoardCenterDialog popWin = new KeyBoardCenterDialog(context, DeviceUtil.getScreenSize(context)[0], dipUnit * 137); 30 | KeyBoardDialog.DialogModel dialogModel = new KeyBoardDialog.DialogModel(); 31 | dialogModel.setType(selectType); 32 | popWin.bindData(dialogModel, new KeyBoardDialog.SelectCallBack() { 33 | @Override 34 | public void selectByType(int type, double value) { 35 | if (type == KeyBoardCenterDialog.TYPE_DIVISION && value == 0.0) { 36 | Toast.makeText(context, "不能除以0,请重新输入", Toast.LENGTH_SHORT).show(); 37 | return; 38 | } 39 | int startColumn = selectRange[0]; 40 | int startRow = selectRange[1]; 41 | int endColumn = selectRange[2]; 42 | int endRow = selectRange[3]; 43 | //针对数据进行批量处理 44 | for (int i = 0; i < dataList.size(); i++) { 45 | if (i < startRow || i > endRow) { 46 | continue; 47 | } 48 | for (int j = startColumn; j <= endColumn; j++) { 49 | Double old = dataList.get(i).get(j); 50 | Double newValue = 0.0; 51 | switch (type) { 52 | case KeyBoardCenterDialog.TYPE_ADD: 53 | newValue = old + value; 54 | break; 55 | case KeyBoardCenterDialog.TYPE_SUB: 56 | newValue = old - value; 57 | break; 58 | case KeyBoardCenterDialog.TYPE_MULTI: 59 | newValue = old * value; 60 | break; 61 | case KeyBoardCenterDialog.TYPE_DIVISION: 62 | newValue = old / value; 63 | break; 64 | case KeyBoardCenterDialog.TYPE_ASSIGN: 65 | newValue = value; 66 | } 67 | dataList.get(i).set(j, newValue); 68 | } 69 | } 70 | excelView.notifyDataColor(selectRange, Color.RED); 71 | excelView.notifyDataChange(tableModel); 72 | } 73 | }); 74 | //显示的坐标位置不一样 75 | popWin.showAtLocation(excelView, Gravity.CENTER, 0, 500); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /app/src/main/java/com/xt/excelview/util/IOHelper.java: -------------------------------------------------------------------------------- 1 | package com.xt.excelview.util; 2 | 3 | import java.io.File; 4 | import java.io.FileOutputStream; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.io.OutputStream; 8 | 9 | public class IOHelper { 10 | public static void copyFileFromInputStream(InputStream input, 11 | File dest) 12 | throws IOException { 13 | OutputStream output = null; 14 | try { 15 | output = new FileOutputStream(dest); 16 | byte[] buf = new byte[1024]; 17 | int bytesRead; 18 | while ((bytesRead = input.read(buf)) != -1) { 19 | output.write(buf, 0, bytesRead); 20 | } 21 | } finally { 22 | input.close(); 23 | output.close(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 |