diff --git a/app/build.gradle.kts b/app/build.gradle.kts index a79da3eada321358d21e6086d5fda1c08f7b88e0..7f2744bbfa3f3fc07ab29aedf85e822fe1742631 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -41,6 +41,7 @@ android { } dependencies { + implementation(files("libs/poishadow-all.jar")) val camerax_version = "1.3.0" implementation("androidx.core:core-ktx:1.6.0") @@ -50,8 +51,9 @@ dependencies { implementation("androidx.navigation:navigation-ui-ktx:2.3.5") implementation("androidx.room:room-runtime:2.4.0") implementation("androidx.room:room-ktx:2.4.0") - implementation("org.apache.poi:poi:5.2.0") - implementation("org.apache.poi:poi-ooxml:5.2.0") +// Implementation is swapped with poishadow-all jar because xls is broken +// implementation("org.apache.poi:poi:5.2.0") +// implementation("org.apache.poi:poi-ooxml:5.2.0") implementation("com.github.PhilJay:MPAndroidChart:v3.1.0") annotationProcessor("androidx.room:room-compiler:2.4.0") ksp("androidx.room:room-compiler:2.4.0") diff --git a/app/libs/poishadow-all.jar b/app/libs/poishadow-all.jar new file mode 100644 index 0000000000000000000000000000000000000000..f192cf4c559b93c7f6238c480204b1f648a15411 Binary files /dev/null and b/app/libs/poishadow-all.jar differ diff --git a/app/src/main/java/com/example/bondoman/types/util/ExcelUtil.kt b/app/src/main/java/com/example/bondoman/types/util/ExcelUtil.kt index ef89d93c1e157f2805e72381cd765b159531d954..7304da78620ec39791cfa8f072a5bf527e666005 100644 --- a/app/src/main/java/com/example/bondoman/types/util/ExcelUtil.kt +++ b/app/src/main/java/com/example/bondoman/types/util/ExcelUtil.kt @@ -4,6 +4,7 @@ import android.content.Context import com.example.bondoman.R import com.example.bondoman.database.entity.TransactionEntity import com.example.bondoman.types.enums.ExcelTypes +import org.apache.poi.hssf.usermodel.HSSFWorkbook import org.apache.poi.ss.usermodel.BorderStyle import org.apache.poi.ss.usermodel.FillPatternType import org.apache.poi.ss.usermodel.IndexedColors @@ -14,6 +15,12 @@ import java.util.Date import java.util.Locale class ExcelUtil(val context: Context) { + init { + System.setProperty("org.apache.poi.javax.xml.stream.XMLInputFactory", "com.fasterxml.aalto.stax.InputFactoryImpl") + System.setProperty("org.apache.poi.javax.xml.stream.XMLOutputFactory", "com.fasterxml.aalto.stax.OutputFactoryImpl") + System.setProperty("org.apache.poi.javax.xml.stream.XMLEventFactory", "com.fasterxml.aalto.stax.EventFactoryImpl") + } + fun exportTransaction( transactionList: List<TransactionEntity>, type: ExcelTypes, @@ -23,23 +30,25 @@ class ExcelUtil(val context: Context) { ExcelTypes.XLS -> ".xls" ExcelTypes.XLSX -> ".xlsx" } + val workbook = when (type){ + ExcelTypes.XLS -> HSSFWorkbook() + ExcelTypes.XLSX -> XSSFWorkbook() + } val file = File( path, "BondomanTransaction" + SimpleDateFormat("yyyy_MM_dd_HH_mm_ss", Locale.getDefault()).format( Date() ) + ext ) - - val workbook = XSSFWorkbook() val workSheet = workbook.createSheet("Transactions") val headerCellStyle = workbook.createCellStyle() - headerCellStyle.setFillForegroundColor(IndexedColors.LIGHT_GREEN.index) - headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND) - headerCellStyle.setBorderTop(BorderStyle.THIN) - headerCellStyle.setBorderBottom(BorderStyle.THIN) - headerCellStyle.setBorderLeft(BorderStyle.THIN) - headerCellStyle.setBorderRight(BorderStyle.THIN) + headerCellStyle.fillForegroundColor = IndexedColors.LIGHT_GREEN.index + headerCellStyle.fillPattern = FillPatternType.SOLID_FOREGROUND + headerCellStyle.borderTop = BorderStyle.THIN + headerCellStyle.borderBottom = BorderStyle.THIN + headerCellStyle.borderLeft = BorderStyle.THIN + headerCellStyle.borderRight = BorderStyle.THIN val headers = arrayOf( context.getString(R.string.transaction_label_number), @@ -50,8 +59,9 @@ class ExcelUtil(val context: Context) { context.getString(R.string.transaction_label_timestamp) ) - val cellStyle = headerCellStyle.copy() - cellStyle.setFillForegroundColor(IndexedColors.WHITE.index) + val cellStyle = workbook.createCellStyle() + cellStyle.cloneStyleFrom(headerCellStyle) + cellStyle.fillForegroundColor = IndexedColors.WHITE.index cellStyle.wrapText = true val firstRow = workSheet.createRow(0)