generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(database): add Excel toolchain functions
Added new ExcelToolchainFunction class in the database module. This class includes functions for handling Excel files, such as checking applicability, executing functions, and converting between markdown and Excel formats.
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
toolsets/database/src/main/kotlin/com/phodal/shire/database/excel/ExcelToolchainFunction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.phodal.shire.database.excel | ||
|
||
import com.intellij.openapi.project.Project | ||
import com.intellij.psi.PsiBinaryFile | ||
import com.intellij.psi.PsiManager | ||
import com.phodal.shirecore.provider.function.ToolchainFunctionProvider | ||
|
||
class ExcelToolchainFunction : ToolchainFunctionProvider { | ||
override fun isApplicable(project: Project, funcName: String): Boolean { | ||
return funcName == "excel" | ||
} | ||
|
||
override fun execute(project: Project, funcName: String, args: List<Any>, allVariables: Map<String, Any?>): Any { | ||
return "excel" | ||
} | ||
|
||
/// markdown to excel | ||
fun markdownToExcel(project: Project, content: String): String { | ||
return "excel" | ||
} | ||
|
||
/// excel to markdown | ||
fun excelToMarkdown(project: Project, filePath: String): String? { | ||
val file = project.baseDir.findFileByRelativePath(filePath) | ||
?: throw IllegalArgumentException("File not found: $filePath") | ||
val excelFile = PsiManager.getInstance(project).findFile(file) | ||
|
||
if (excelFile !is PsiBinaryFile) { | ||
throw IllegalArgumentException("File is not a binary file: $filePath") | ||
} | ||
|
||
// val config = BaseExtractorConfig() | ||
// val xlsxValuesExtractor = XlsxExtractorFactory().createExtractor(config) | ||
// xlsxValuesExtractor.startExtraction() | ||
return excelFile?.text | ||
} | ||
} |