Skip to content

Commit

Permalink
feat(database): add Excel toolchain functions
Browse files Browse the repository at this point in the history
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
phodal committed Sep 20, 2024
1 parent f54e0c0 commit 868510c
Showing 1 changed file with 37 additions and 0 deletions.
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
}
}

0 comments on commit 868510c

Please sign in to comment.