Documentation
¶
Index ¶
- Constants
- Variables
- func CheckTableData(tableData TableData) ([]string, bool)
- func Connect() *sql.DB
- func CovertTableDefineToMap(tableDefineList []TableDefine) map[string]TableDefine
- func CreateStyle(xlsx *excelize.File, styleTmpl string, cellFont string, backColor string) int
- func CreateTemplate(tblIn *TableIn)
- func ExecuteQuery()
- func ExportDataToXlsx(db *sql.DB, mTableDefine map[string]TableDefine, mSql map[string]string, ...)
- func GetColRowInMergeCell(mergeCell []excelize.MergeCell, colIdx int, row int) (colIdxMergeStart int, colIdxMergeEnd int)
- func GetContinousCountInCol(xlsx *excelize.File, sheetName string, col string, rowStart int) int
- func GetContinousCountInRow(xlsx *excelize.File, sheetName string, col string, rowStart int) int
- func GetContinousValueInRow(xlsx *excelize.File, sheetName string, colIdxStart int, row int) []string
- func GetCsvValue(v string, t string, dbType int) string
- func GetRange(c string, r int) string
- func GetRowTableName(xlsx *excelize.File, sheetName string, tableName string, ...) (int, error)
- func GetTableData(testDataFile string, tableNames []string, tmplCfg *TemplateConfig) map[string]TableData
- func GetValueForJsonType(v string, t string) string
- func GetValueForType(v string, t string, flag string) string
- func ToCsv(tableData map[string]TableData, tblIn *TableIn) []string
- func ToCsvSingle(tableData TableData, tblIn *TableIn) []string
- func ToSqlInsert(tableDatas map[string]TableData, tableDefine map[string]TableDefine) []string
- func ToSqlInsertSingle(tableData TableData, tableDefine TableDefine) []string
- type ColumnInfo
- type JsonItemInfo
- type TableData
- type TableDefine
- type TableDesineConfig
- type TableIn
- type TemplateConfig
Constants ¶
View Source
const COLOR_COLUMN_HEAD = "92D050"
View Source
const COLOR_JSON_HEAD_ITEM = "FABF8F"
View Source
const COLOR_TABLE_LOGICAL_NAME = "00B0F0"
View Source
const COLOR_TABLE_NAME = "92CDDC"
View Source
const CONNECT_STRING = "host=%s port=%d user=%s password=%s dbname=%s sslmode=disable"
View Source
const DB_MYSQL int = 4
View Source
const DB_ORACLE int = 1
View Source
const DB_POSTGRES int = 3
View Source
const DB_SQLITE int = 5
View Source
const DB_SQLSERVER int = 2
View Source
const DEFALT_SQL = " select * from " + PLACEHOLDER_TABLE + " "
View Source
const DEFAULT_TEMPLATE_FILE = "./table/template.xlsx"
View Source
const FLAG_CSV = "CSV"
View Source
const FLAG_SQL = "SQL"
View Source
const FONT_MINGCHAO = "MS 明朝"
View Source
const PLACEHOLDER_TABLE = "#TABLE#"
View Source
const STYLE_DATA string = `` /* 298-byte string literal not displayed */
View Source
const STYLE_HEAD string = `` /* 358-byte string literal not displayed */
View Source
const TABLE_IN_FILE string = "./table/table_input.yml"
Variables ¶
View Source
var ALPHA = regexp.MustCompile("^[a-zA-Z]*")
View Source
var NUM = regexp.MustCompile("[0-9]*$")
View Source
var S_BOOL = []string{"bool", "boolean"}
View Source
var S_DATE_TIME = []string{"date", "time"}
View Source
var S_JSON = []string{"json", "jsonb"}
View Source
var S_NUMBER = []string{"integer", "number", "int"}
View Source
var S_TEXT = []string{"char", "varchar", "varchar2", "text"}
View Source
var S_YES = []string{"○", "〇", "Y"}
Functions ¶
func CheckTableData ¶
func CovertTableDefineToMap ¶
func CovertTableDefineToMap(tableDefineList []TableDefine) map[string]TableDefine
表定义一览转换成映射
键为表名,值为表定义
func CreateStyle ¶
样式
func ExecuteQuery ¶
func ExecuteQuery()
func ExportDataToXlsx ¶
func ExportDataToXlsx(db *sql.DB, mTableDefine map[string]TableDefine, mSql map[string]string, tmplCfg *TemplateConfig, tmplFile string, testDataFile string)
从数据库表中获取数据,反映到Xlsx模板
sSql为空字符串的场合,抽取表中所有数据
func GetColRowInMergeCell ¶
func GetColRowInMergeCell(mergeCell []excelize.MergeCell, colIdx int, row int) (colIdxMergeStart int, colIdxMergeEnd int)
在所有合并的单元格中找到目标单元格所在的合并单元格的行和列
func GetContinousCountInCol ¶
获取指定列里连续有数据的行数
func GetContinousCountInRow ¶
获取指定行里连续有数据的列数
func GetContinousValueInRow ¶
func GetContinousValueInRow(xlsx *excelize.File, sheetName string, colIdxStart int, row int) []string
获取指定行里连续的数据
func GetRowTableName ¶
func GetRowTableName(xlsx *excelize.File, sheetName string, tableName string, tmplCfg *TemplateConfig) (int, error)
获取表名所在行(列为模板配置文件所在列)
查找表名在Sheet里的位置,作为相对偏移位置
func GetTableData ¶
func GetTableData(testDataFile string, tableNames []string, tmplCfg *TemplateConfig) map[string]TableData
把Excel中的数据导入到数据库
func GetValueForJsonType ¶
func ToCsvSingle ¶
func ToSqlInsert ¶
func ToSqlInsert(tableDatas map[string]TableData, tableDefine map[string]TableDefine) []string
func ToSqlInsertSingle ¶
func ToSqlInsertSingle(tableData TableData, tableDefine TableDefine) []string
Types ¶
type ColumnInfo ¶
type ColumnInfo struct { No string ColumnLogicalName string ColumnName string Type string JsonItem []JsonItemInfo Length int LengthEx int PK bool NotNull bool Default string Description string Remark string IsJson bool Data string }
列
type JsonItemInfo ¶
type JsonItemInfo struct { ItemNo string ItemLogicalName string ItemName string ItemType string ItemLength int ItemLengthEx int }
JSON(JSONB)项目
type TableData ¶
type TableData struct { TableLogicalName string TableName string DataList [][]ColumnInfo ExInfo string }
表数据
func GetSingleTableData ¶
func GetSingleTableData(testDataFile string, tableName string, tmplCfg *TemplateConfig) TableData
把Excel中的数据导入到数据库
type TableDefine ¶
type TableDefine struct { TableLogicalName string TableName string Column []ColumnInfo ExInfo string HasJsonColumn bool }
表
type TableDesineConfig ¶
type TableDesineConfig struct { SheetNameTableDefine []string `yaml:"sheetNameTableDefine"` ColNo string `yaml:"colNo"` ColColumnLogicalName string `yaml:"colColumnLogicalName"` ColColumnName string `yaml:"colColumnName"` ColPK string `yaml:"colPK"` ColType string `yaml:"colType"` ColLength string `yaml:"colLength"` ColItemLogicalName string `yaml:"colItemLogicalName"` ColItemName string `yaml:"colItemName"` ColItemType string `yaml:"colItemType"` ColItemLength string `yaml:"colItemLength"` ColNotNull string `yaml:"colNotNull"` ColDefault string `yaml:"colDefault"` ColDescription string `yaml:"colDescription"` ColRemark string `yaml:"colRemark"` StartRow int `yaml:"startRow"` LastRow int }
表定义配置
type TableIn ¶
type TableIn struct { // 表设计文件(XLSX) TableDesineFile []string `yaml:"tableDesineFile"` // 表设计 配置文件 TableDesineConfigFile string `yaml:"tableDesineConfigFile"` // 表定义文件(JSON) TableDefineFile string `yaml:"tableDefineFile"` // 数据模板 配置文件 TemplateConfigFile string `yaml:"templateConfigFile"` // 数据模板输出对象表 TemplateOutTargetTable []string `yaml:"templateOutTargetTable"` // 数据模板输出文件 TemplateFile string `yaml:"templateFile"` // 测试数据文件 TestDataFile string `yaml:"testDataFile"` // 数据库类型 DatabaseType int `yaml:"databaseType"` // CSV目录 CsvPath string `yaml:"csvPath"` }
处理输入
var GlobalTableIn TableIn
type TemplateConfig ¶
type TemplateConfig struct { IsMultiSheet bool `yaml:"isMultiSheet"` SingleSheetName string `yaml:"singleSheetName"` CountDefaultdata int `yaml:"countDefaultdata"` CountSeparateRow int `yaml:"countSeparateRow"` ColTableLogicalName string `yaml:"colTableLogicalName"` ColTableName string `yaml:"colTableName"` RowTableLogicalName int `yaml:"rowTableLogicalName"` RowTableName int `yaml:"rowTableName"` RowColumnLogicalName int `yaml:"rowColumnLogicalName"` RowColumnName int `yaml:"rowColumnName"` RowType int `yaml:"rowType"` RowLength int `yaml:"rowLength"` RowJsonColumnLogicalName int `yaml:"rowJsonColumnLogicalName"` RowJsonColumnName int `yaml:"rowJsonColumnName"` RowJsonType int `yaml:"rowJsonType"` RowItemLogicalName int `yaml:"rowItemLogicalName"` RowItemName int `yaml:"rowItemName"` RowItemType int `yaml:"rowItemType"` RowItemLength int `yaml:"rowItemLength"` StartColData string `yaml:"startColData"` CellFont string `yaml:"cellFont"` TableLogicalNameBackColor string `yaml:"tableLogicalNameBackColor"` TableNameBackColor string `yaml:"tableNameBackColor"` ColumnHeadBackColor string `yaml:"columnHeadBackColor"` JsonHeadItemBackColor string `yaml:"jsonHeadItemBackColor"` }
模板定义配置
Click to show internal directories.
Click to hide internal directories.