Skip to content

Commit 29295d4

Browse files
author
m.r
committed
add README, remove logs and update/create workflow
1 parent 6fd9e08 commit 29295d4

File tree

9 files changed

+246
-25
lines changed

9 files changed

+246
-25
lines changed

.github/workflows/build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
2626

2727
- name: Build with Gradle
28-
run: ./gradlew build
28+
run: ./gradlew -b build-github.gradle build
2929

3030
- name: Upload build artifacts
3131
uses: actions/upload-artifact@v4
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created
6+
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle
7+
8+
name: Manually Gradle Package
9+
on:
10+
workflow_dispatch:
11+
inputs:
12+
branch:
13+
description: 'Test Branch'
14+
required: true
15+
default: 'main'
16+
17+
jobs:
18+
build:
19+
20+
runs-on: ubuntu-latest
21+
permissions:
22+
contents: read
23+
packages: write
24+
25+
steps:
26+
- uses: actions/checkout@v4
27+
- name: Set up JDK 11
28+
uses: actions/setup-java@v4
29+
with:
30+
java-version: '11'
31+
distribution: 'temurin'
32+
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
33+
settings-path: ${{ github.workspace }} # location for the settings.xml file
34+
35+
# - name: Setup Gradle
36+
# uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
37+
- name: Setup Gradle
38+
uses: gradle/actions/setup-gradle@v4
39+
40+
- name: Build with Gradle
41+
run: ./gradlew -b build-github.gradle build
42+
43+
# The USERNAME and TOKEN need to correspond to the credentials environment variables used in
44+
# the publishing section of your build.gradle
45+
- name: Publish to GitHub Packages
46+
run: ./gradlew -b build-github.gradle publish
47+
env:
48+
USERNAME: ${{ github.actor }}
49+
TOKEN: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# MR Excel
2+
3+
MR Excel is a tool for generating Excel files. The implementation of this library is similar to ["`MR Excel JavaScript`"](https://github.com/mohammadrezaeicode/mr-excel-repo). You can use the documentation from that repository for reference. [example](https://github.com/mohammadrezaeicode/mr-excel-java-example-gallery) Requirement:**`JDK 11+`**
4+
5+
## Related Projects
6+
7+
The following list includes new repositories related to this project. Documentation and improvements for these projects can be found in the repositories below.
8+
9+
- **`MR Excel Java`**:A similar project using Java is in development. The release version is coming soon; currently, it is available as a snapshot version.["`repository`"](https://github.com/mohammadrezaeicode/mr-excel-java)
10+
11+
- **`MR Excel Editor`**: An editor that utilizes the library is currently under development. At present, it only generates simple results.["`repository`"](https:///github.com/mohammadrezaeicode/mr-excel-editor)["`Demo`"](https://mohammadrezaeicode.github.io/mr-excel-editor/)
12+
13+
## Import in `Maven` project
14+
15+
To use the dependency, follow the structure below:
16+
17+
1. `Generate a GitHub token` with access to `read:packages` and add the server to `~/.m2/setting.xml`. You can find the exact structure in this [link](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-apache-maven-registry#authenticating-with-a-personal-access-token).
18+
19+
```xml
20+
<servers>
21+
<server>
22+
<id></id>
23+
<username></username>
24+
<password></password>
25+
</server>
26+
</servers>
27+
```
28+
29+
2. Add the repository to your `pom.xml` file:
30+
31+
```xml
32+
<repositories>
33+
<repository>
34+
<id>github</id>
35+
<url>https://maven.pkg.github.com/mohammadrezaeicode/excel</url>
36+
<releases>
37+
<enabled>true</enabled>
38+
</releases>
39+
<snapshots>
40+
<enabled>true</enabled>
41+
</snapshots>
42+
</repository>
43+
</repositories>
44+
```
45+
46+
3. Add the library to your `dependencies`:
47+
48+
```xml
49+
<dependency>
50+
<groupId>io.github.mohammadrezaeicode</groupId>
51+
<artifactId>excel</artifactId>
52+
<version>0.1-SNAPSHOT</version>
53+
</dependency>
54+
```
55+
56+
## Import in `Gradle` project
57+
58+
To use the dependency, follow the structure below:
59+
60+
1. **Generate a GitHub token** with access to `read:packages` and configure your `~/.gradle/gradle.properties` file:
61+
62+
```properties
63+
gpr.user=YOUR_GITHUB_USERNAME
64+
gpr.token=YOUR_GITHUB_TOKEN
65+
```
66+
67+
2. **Add the repository to your `build.gradle` file**:
68+
69+
```groovy
70+
repositories {
71+
maven {
72+
url = uri("https://maven.pkg.github.com/mohammadrezaeicode/excel")
73+
credentials {
74+
username = project.findProperty("gpr.user") ?: System.getenv("USERNAME")
75+
password = project.findProperty("gpr.token") ?: System.getenv("TOKEN")
76+
}
77+
}
78+
}
79+
```
80+
81+
3. **Add the library to your dependencies**:
82+
83+
```groovy
84+
dependencies {
85+
implementation 'io.github.mohammadrezaeicode:excel:0.1-SNAPSHOT'
86+
}
87+
```
88+
89+

build-github.gradle

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
plugins {
2+
id 'java-library'
3+
id 'maven-publish'
4+
5+
}
6+
compileJava {
7+
options.encoding = "UTF-8"
8+
}
9+
compileTestJava {options.encoding = "UTF-8"}
10+
11+
12+
group = 'io.github.mohammadrezaeicode'
13+
version = '0.1-SNAPSHOT'
14+
15+
java {
16+
withJavadocJar()
17+
withSourcesJar()
18+
}
19+
20+
repositories {
21+
mavenCentral()
22+
}
23+
24+
dependencies {
25+
testImplementation platform('org.junit:junit-bom:5.9.1')
26+
testImplementation 'org.junit.jupiter:junit-jupiter'
27+
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
28+
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
29+
compileOnly 'org.projectlombok:lombok:1.18.36'
30+
annotationProcessor 'org.projectlombok:lombok:1.18.36'
31+
}
32+
33+
publishing {
34+
publications {
35+
gpr(MavenPublication) {
36+
artifactId = "excel"
37+
from components.java
38+
versionMapping {
39+
usage('java-api') {
40+
fromResolutionOf('runtimeClasspath')
41+
}
42+
usage('java-runtime') {
43+
fromResolutionResult()
44+
}
45+
}
46+
pom {
47+
name = 'MR Excel'
48+
description = 'A versatile Java library for effortlessly generating .xlsx files from input objects. Seamlessly create Excel spreadsheets with data, formatting, formulas, and more.'
49+
url = 'https://github.com/mohammadrezaeicode/mr-excel-java'
50+
// properties = [
51+
// myProp: "value",
52+
// "prop.with.dots": "anotherValue"
53+
// ]
54+
licenses {
55+
license {
56+
name = 'The Apache License, Version 2.0'
57+
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
58+
}
59+
}
60+
developers {
61+
developer {
62+
id = 'MohammadR'
63+
name = 'Mohammad Rezaei'
64+
email = 'mohammadrezaeicode@gmail.com'
65+
}
66+
}
67+
scm {
68+
connection = 'scm:git:https://github.com/mohammadrezaeicode/mr-excel-java.git'
69+
developerConnection = 'scm:git:git@github.com:mohammadrezaeicode/mr-excel-java.git'
70+
url = 'https://github.com/mohammadrezaeicode/mr-excel-java'
71+
}
72+
repositories {
73+
maven {
74+
name = "GitHubPackages"
75+
url = uri("https://maven.pkg.github.com/mohammadrezaeicode/mr-excel-java") // replace OWNER and REPOSITORY with your GitHub username and your repository name
76+
credentials {
77+
username = project.findProperty("gpr.user") ?: System.getenv("USERNAME")
78+
password = project.findProperty("gpr.key") ?: System.getenv("TOKEN")
79+
}
80+
}
81+
}
82+
}
83+
}
84+
}
85+
}
86+
87+
test {
88+
useJUnitPlatform()
89+
}
90+
tasks.withType(JavaCompile) {
91+
options.encoding = 'UTF-8'
92+
}
93+
javadoc {
94+
if(JavaVersion.current().isJava9Compatible()) {
95+
options.addBooleanOption('html5', true)
96+
}
97+
}

src/main/java/io/github/mohammadrezaeicode/excel/Main.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
public class Main {
1515
public static void main(String[] args) throws IOException, InvocationTargetException, IllegalAccessException {
16-
System.out.println(Optional.ofNullable(null).isPresent());
1716

1817
// ExcelTable1 excelTable1= ExcelTable1.builder()
1918
// .sheet(Arrays.asList(

src/main/java/io/github/mohammadrezaeicode/excel/function/GenerateExcel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import static io.github.mohammadrezaeicode.excel.util.CommentUtil.commentConvertor;
2727

2828
public class GenerateExcel {
29-
public static <T> Result generateHeaderAndGenerateExcel(List<SheetGenerator<T>> sheetData, ExcelTableOption options) throws InvocationTargetException, IllegalAccessException, IOException {
29+
public static <T> Result generateHeaderAndGenerateExcel(List<SheetGenerator<T>> sheetData, ExcelTableOption options) throws InvocationTargetException, IllegalAccessException, IOException, NoSuchMethodException {
3030
List<Sheet1> sheetList = new ArrayList<>();
3131
for (SheetGenerator<T> sheet : sheetData) {
3232
sheetList.add(SheetGeneratorUtils.generateSheet(sheet.getData(), sheet.getHeaderClass(), sheet.getApplyHeaderOptionFunction()));
@@ -42,7 +42,7 @@ public static <T> Result generateHeaderAndGenerateExcel(List<SheetGenerator<T>>
4242
return generateExcel(exOb, "");
4343
}
4444

45-
public static <T> Result generateHeaderAndGenerateExcel(List<T> data, ExcelTableOption options, Class headerClass, Function<List<Header>, List<Header>> applyHeaderOptionFunction) throws InvocationTargetException, IllegalAccessException, IOException {
45+
public static <T> Result generateHeaderAndGenerateExcel(List<T> data, ExcelTableOption options, Class headerClass, Function<List<Header>, List<Header>> applyHeaderOptionFunction) throws InvocationTargetException, IllegalAccessException, IOException, NoSuchMethodException {
4646
var exOb = ExcelTable1.builder()
4747
.sheet(
4848
Collections.singletonList(SheetGeneratorUtils.<T>generateSheet(data, headerClass, applyHeaderOptionFunction))

src/main/java/io/github/mohammadrezaeicode/excel/util/ColumnUtils.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,8 @@ public static ShapeRC getColRowBaseOnRefString(
1313
List<String> cols
1414
){
1515
String column = refString.replaceAll("[0-9]", "");
16-
int row = 0;
17-
try {
18-
row= Integer.parseInt(refString.substring(column.length()));
19-
}catch (NumberFormatException exception){
20-
System.out.println("");
21-
}
16+
int row = Integer.parseInt(refString.substring(column.length()));
17+
2218
row = Math.max(0, row - 1);
2319
int colIndex = cols.indexOf(column);
2420
if (colIndex < 0) {

src/main/java/io/github/mohammadrezaeicode/excel/util/Process.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@
1212
import java.util.List;
1313

1414
public class Process {
15-
public static List<Header> findAnnotation(Class headerClass) {
15+
public static List<Header> findAnnotation(Class headerClass) throws NoSuchMethodException, SecurityException {
1616
Class<? extends Object> cls = headerClass;
1717
List<Field> presentField = new ArrayList<>();
1818
List<String> textName = new ArrayList<>();
1919
List<String> methodName = new ArrayList<>();
20-
Method[] methods = cls.getDeclaredMethods();
21-
System.out.println(methods.length);
22-
System.out.println(methods[0].getName());
2320
Field[] fields = cls.getDeclaredFields();
2421
// Map<String,String> fieldVsMethod=new HashMap<>();
2522
for (Field field : fields) {
@@ -43,7 +40,6 @@ public static List<Header> findAnnotation(Class headerClass) {
4340
if (field.isAnnotationPresent(Options.class)) {
4441
Options options = field.getAnnotation(Options.class);
4542
String anTitle = new String(options.title().getBytes(), StandardCharsets.UTF_8);
46-
System.out.println(anTitle);
4743
if (anTitle.length() > 0) {
4844
title = anTitle;
4945
}
@@ -52,22 +48,17 @@ public static List<Header> findAnnotation(Class headerClass) {
5248
methodName.add(getterMethodName);
5349
presentField.add(field);
5450
// fieldVsMethod.put(getterMethodName,fieldName);
55-
} else {
56-
System.out.println("field been excluded" + field.getName());
57-
}
51+
}
5852
}
5953
List<Header> header = new ArrayList<>();
6054
int index = 0;
6155
for (String name : methodName) {
6256

63-
try {
64-
Method m = cls.getMethod(name);
65-
header.add(new Header(presentField.get(index).getName(), textName.get(index), m));
57+
Method m = cls.getMethod(name);
58+
header.add(new Header(presentField.get(index).getName(), textName.get(index), m));
6659
// String result= (String) m.invoke(obj);
6760
// System.out.println(result);
68-
} catch (NoSuchMethodException error) {
69-
System.out.println("method not found");
70-
}
61+
7162
index++;
7263
}
7364
return header;

src/main/java/io/github/mohammadrezaeicode/excel/util/SheetGeneratorUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import java.util.function.Function;
1010

1111
public class SheetGeneratorUtils {
12-
public static <T> Sheet1 generateSheet(List<T> data, Class headerClass, Function<List<Header>,List<Header>> applyHeaderOptionFunction){
12+
public static <T> Sheet1 generateSheet(List<T> data, Class headerClass, Function<List<Header>,List<Header>> applyHeaderOptionFunction) throws NoSuchMethodException {
1313
List<Header> headers=new ArrayList<>();
1414
if(data.size()>0){
1515
var firstRecord=data.get(0);

0 commit comments

Comments
 (0)