kotlin-excel-dsl - Kotlin DSL से Excel फ़ाइलें type-safe तरीके से बनाना
(github.com/clroot)Kotlin में हर बार Excel फ़ाइल बनाते समय Apache POI का लंबा-चौड़ा कोड असुविधाजनक लगता था। एक सेल बनाने के लिए भी Workbook → Sheet → Row → Cell से होकर गुजरना पड़ता है, और style लागू करना तो उससे भी अधिक जटिल है.
इसलिए मैंने Kotlin DSL के साथ Excel creation को सरल बनाने वाली एक लाइब्रेरी बनाई है।
GitHub: https://github.com/clroot/kotlin-excel-dsl
विशेषताएँ
- DSL + annotation hybrid: जटिल मामलों में DSL, सरल मामलों में
@Excel,@Columnannotation - Type-safe: compile time पर configuration errors की जाँच
- CSS style syntax: सहज style definition
- Built-in themes: Modern, Minimal, Classic
- Header groups: multi-row headers और automatic cell merge
उपयोग उदाहरण
// DSL 방식
excel {
sheet<User>("Users") {
column("이름") { it.name }
column("나이") { it.age }
column("가입일") { it.joinedAt }
rows(users)
}
}.writeTo(FileOutputStream("users.xlsx"))
// 어노테이션 방식
@Excel
data class User(
@Column("이름") val name: String,
@Column("나이") val age: Int
)
excelOf(users).writeTo(output)
style लागू करना
excel {
styles {
header { bold(); backgroundColor(Color.GRAY) }
column("금액") {
body { align(Alignment.RIGHT); numberFormat("#,##0") }
}
}
// ...
}
इंस्टॉलेशन
implementation("io.clroot.excel:excel-dsl:0.1.0")
इसे Kotlin 2.2.0+ और JDK 21+ वातावरण में इस्तेमाल किया जा सकता है। फ़ीडबैक का स्वागत है!
1 टिप्पणियां
यह व्यक्तिगत तौर पर मुझे चाहिए थी ऐसी लाइब्रेरी है, इसलिए लगता है कि इसे काफ़ी उपयोगी तरीके से इस्तेमाल किया जा सकेगा! व्यक्तिगत तौर पर यह Excel-आधारित लाइब्रेरी है, लेकिन सोचता हूँ कि अगर इसमें CSV या PDF export फीचर भी शामिल हो जाएँ तो कैसा रहेगा।