diff --git a/go.mod b/go.mod index 1f4886bcd0..e935cf54e1 100644 --- a/go.mod +++ b/go.mod @@ -76,6 +76,7 @@ require ( require ( dario.cat/mergo v1.0.0 // indirect + github.com/360EntSecGroup-Skylar/excelize v1.4.1 // indirect github.com/BurntSushi/toml v1.3.2 // indirect github.com/KyleBanks/depth v1.2.1 // indirect github.com/Microsoft/go-winio v0.6.1 // indirect @@ -140,6 +141,7 @@ require ( github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect github.com/oklog/run v1.0.0 // indirect github.com/oklog/ulid v1.3.1 // indirect github.com/opentracing/opentracing-go v1.1.0 // indirect diff --git a/go.sum b/go.sum index 9a18da7788..88cf0efe27 100644 --- a/go.sum +++ b/go.sum @@ -19,6 +19,8 @@ cloud.google.com/go/storage v1.10.0 h1:STgFzyU5/8miMl0//zKh2aQeTyeaUH3WN9bSUiJ09 dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +github.com/360EntSecGroup-Skylar/excelize v1.4.1 h1:l55mJb6rkkaUzOpSsgEeKYtS6/0gHwBYyfo5Jcjv/Ks= +github.com/360EntSecGroup-Skylar/excelize v1.4.1/go.mod h1:vnax29X2usfl7HHkBrX5EvSCJcmH3dT9luvxzu8iGAE= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= @@ -620,6 +622,8 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= +github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= github.com/montanaflynn/stats v0.0.0-20151014174947-eeaced052adb/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= github.com/montanaflynn/stats v0.0.0-20180911141734-db72e6cae808/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= @@ -822,6 +826,7 @@ github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoH github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.2.3-0.20181224173747-660f15d67dbb/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= diff --git a/sqle/api/controller/v1/instance_audit_plan.go b/sqle/api/controller/v1/instance_audit_plan.go index 2d62f682c1..dfaaa869ea 100644 --- a/sqle/api/controller/v1/instance_audit_plan.go +++ b/sqle/api/controller/v1/instance_audit_plan.go @@ -1132,13 +1132,14 @@ func GetInstanceAuditPlanSQLData(c echo.Context) error { } type GetAuditPlanSQLExportReqV1 struct { - OrderBy string `json:"order_by"` - IsAsc bool `json:"is_asc"` - Filters []Filter `json:"filter_list"` + OrderBy string `json:"order_by"` + IsAsc bool `json:"is_asc"` + Filters []Filter `json:"filter_list"` + ExportFormat utils.ExportFormat `json:"export_format" enums:"csv,excel" example:"excel"` // 导出格式:csv 或 excel } -// @Summary 导出指定扫描任务的 SQL CSV 列表 -// @Description export audit plan SQL report as CSV +// @Summary 导出指定扫描任务的 SQL 列表 +// @Description export audit plan SQL report as CSV or Excel // @Id getInstanceAuditPlanSQLExportV1 // @Tags instance_audit_plan // @Security ApiKeyAuth @@ -1193,29 +1194,34 @@ func GetInstanceAuditPlanSQLExport(c echo.Context) error { return controller.JSONBaseErrorReq(c, err) } - csvBuilder := utils.NewCSVBuilder() + // 确定导出格式,默认为excel + exportFormat := utils.NormalizeExportFormat(&req.ExportFormat) - csvHeader := make([]string, len(head)) + // 准备表头数据 + header := make([]string, len(head)) for col, h := range head { - csvHeader[col] = locale.Bundle.LocalizeMsgByCtx(c.Request().Context(), h.Desc) - } - if err = csvBuilder.WriteHeader(csvHeader); err != nil { - return controller.JSONBaseErrorReq(c, err) + header[col] = locale.Bundle.LocalizeMsgByCtx(c.Request().Context(), h.Desc) } + + // 准备行数据 + rowData := make([][]string, 0, len(rows)) for _, rowMap := range rows { - csvRow := make([]string, len(head)) + row := make([]string, len(head)) for col, h := range head { - csvRow[col] = rowMap[h.Name] - } - if err = csvBuilder.WriteRow(csvRow); err != nil { - return controller.JSONBaseErrorReq(c, err) + row[col] = rowMap[h.Name] } + rowData = append(rowData, row) } - fileName := fmt.Sprintf("sql_export_%s_%s.csv", ap.Type, time.Now().Format("20060102150405")) - c.Response().Header().Set(echo.HeaderContentDisposition, mime.FormatMediaType("attachment", map[string]string{"filename": fileName})) + // 使用通用的导出方法 + fileNamePrefix := fmt.Sprintf("sql_export_%s", ap.Type) + exportResult, err := utils.ExportData(header, rowData, fileNamePrefix, exportFormat) + if err != nil { + return controller.JSONBaseErrorReq(c, err) + } - return c.Blob(http.StatusOK, "text/csv", csvBuilder.FlushAndGetBuffer().Bytes()) + c.Response().Header().Set(echo.HeaderContentDisposition, mime.FormatMediaType("attachment", map[string]string{"filename": exportResult.FileName})) + return c.Blob(http.StatusOK, exportResult.ContentType, exportResult.Content) } func ConvertFilterTipsToRes(fts []auditplan.FilterTip) []FilterTip { diff --git a/sqle/api/controller/v1/workflow.go b/sqle/api/controller/v1/workflow.go index a27e3a05d9..2d3a3f1b92 100644 --- a/sqle/api/controller/v1/workflow.go +++ b/sqle/api/controller/v1/workflow.go @@ -1568,11 +1568,12 @@ type ExportWorkflowReqV1 struct { FilterTaskExecuteStartTimeFrom string `json:"filter_task_execute_start_time_from" query:"filter_task_execute_start_time_from"` FilterTaskExecuteStartTimeTo string `json:"filter_task_execute_start_time_to" query:"filter_task_execute_start_time_to"` FuzzyKeyword string `json:"fuzzy_keyword" query:"fuzzy_keyword"` + ExportFormat string `json:"export_format" query:"export_format" enums:"csv,excel" example:"excel"` // 导出格式:csv 或 excel,默认为 excel } // ExportWorkflowV1 // @Summary 导出工单 -// @Description export workflow +// @Description export workflow as CSV or Excel // @Id exportWorkflowV1 // @Tags workflow // @Security ApiKeyAuth @@ -1588,6 +1589,7 @@ type ExportWorkflowReqV1 struct { // @Param filter_task_instance_id query string false "filter instance id" // @Param project_name path string true "project name" // @Param fuzzy_keyword query string false "fuzzy matching subject/workflow_id/desc" +// @Param export_format query string false "export format" Enums(csv,excel) "export format: csv or excel, default is excel" // @Success 200 {file} file "export workflow" // @Router /v1/projects/{project_name}/workflows/exports [get] func ExportWorkflowV1(c echo.Context) error { diff --git a/sqle/api/controller/v2/sql_manage.go b/sqle/api/controller/v2/sql_manage.go index 5759356a5d..06d44a9a33 100644 --- a/sqle/api/controller/v2/sql_manage.go +++ b/sqle/api/controller/v2/sql_manage.go @@ -67,8 +67,8 @@ func GetSqlManageList(c echo.Context) error { } type ExportSqlManagesReq struct { - FuzzySearchSqlFingerprint *string `query:"fuzzy_search_sql_fingerprint" json:"fuzzy_search_sql_fingerprint,omitempty"` - FilterAssignee *string `query:"filter_assignee" json:"filter_assignee,omitempty"` + FuzzySearchSqlFingerprint *string `query:"fuzzy_search_sql_fingerprint" json:"fuzzy_search_sql_fingerprint,omitempty"` + FilterAssignee *string `query:"filter_assignee" json:"filter_assignee,omitempty"` FilterByEnvironmentTag *string `query:"filter_by_environment_tag" json:"filter_by_environment_tag,omitempty"` FilterInstanceID *string `query:"filter_instance_id" json:"filter_instance_id,omitempty"` FilterSource *string `query:"filter_source" json:"filter_source,omitempty"` @@ -83,11 +83,12 @@ type ExportSqlManagesReq struct { FuzzySearchSchemaName *string `query:"fuzzy_search_schema_name" json:"fuzzy_search_schema_name,omitempty"` SortField *string `query:"sort_field" json:"sort_field,omitempty" valid:"omitempty,oneof=first_appear_timestamp last_receive_timestamp fp_count" enums:"first_appear_timestamp,last_receive_timestamp,fp_count"` SortOrder *string `query:"sort_order" json:"sort_order,omitempty" valid:"omitempty,oneof=asc desc" enums:"asc,desc"` + ExportFormat *string `query:"export_format" json:"export_format,omitempty" enums:"csv,excel" example:"excel"` // 导出格式:csv 或 excel,默认为 excel } // ExportSqlManagesV2 // @Summary 导出SQL管控 -// @Description export sql manage +// @Description export sql manage as CSV or Excel // @Id exportSqlManageV2 // @Tags SqlManage // @Security ApiKeyAuth @@ -108,6 +109,7 @@ type ExportSqlManagesReq struct { // @Param fuzzy_search_schema_name query string false "fuzzy search schema name" // @Param sort_field query string false "sort field" Enums(first_appear_timestamp,last_receive_timestamp,fp_count) // @Param sort_order query string false "sort order" Enums(asc,desc) +// @Param export_format query string false "export format" Enums(csv,excel) "export format: csv or excel, default is excel" // @Success 200 {file} file "export sql manage" // @Router /v2/projects/{project_name}/sql_manages/exports [get] func ExportSqlManagesV2(c echo.Context) error { diff --git a/sqle/docs/docs.go b/sqle/docs/docs.go index 5db5c3f9ce..32c4b2393e 100644 --- a/sqle/docs/docs.go +++ b/sqle/docs/docs.go @@ -3766,11 +3766,11 @@ var doc = `{ "ApiKeyAuth": [] } ], - "description": "export audit plan SQL report as CSV", + "description": "export audit plan SQL report as CSV or Excel", "tags": [ "instance_audit_plan" ], - "summary": "导出指定扫描任务的 SQL CSV 列表", + "summary": "导出指定扫描任务的 SQL 列表", "operationId": "getInstanceAuditPlanSQLExportV1", "parameters": [ { @@ -8073,7 +8073,7 @@ var doc = `{ "ApiKeyAuth": [] } ], - "description": "export workflow", + "description": "export workflow as CSV or Excel", "tags": [ "workflow" ], @@ -8161,6 +8161,16 @@ var doc = `{ "description": "fuzzy matching subject/workflow_id/desc", "name": "fuzzy_keyword", "in": "query" + }, + { + "enum": [ + "csv", + "excel" + ], + "type": "string", + "description": "export format", + "name": "export_format", + "in": "query" } ], "responses": { @@ -11740,7 +11750,7 @@ var doc = `{ "ApiKeyAuth": [] } ], - "description": "export sql manage", + "description": "export sql manage as CSV or Excel", "tags": [ "SqlManage" ], @@ -11878,6 +11888,16 @@ var doc = `{ "description": "sort order", "name": "sort_order", "in": "query" + }, + { + "enum": [ + "csv", + "excel" + ], + "type": "string", + "description": "export format", + "name": "export_format", + "in": "query" } ], "responses": { @@ -15855,6 +15875,15 @@ var doc = `{ "v1.GetAuditPlanSQLExportReqV1": { "type": "object", "properties": { + "export_format": { + "description": "导出格式:csv 或 excel,默认为 excel", + "type": "string", + "enum": [ + "csv", + "excel" + ], + "example": "excel" + }, "filter_list": { "type": "array", "items": { diff --git a/sqle/docs/swagger.json b/sqle/docs/swagger.json index 216ef29b7d..f638d38913 100644 --- a/sqle/docs/swagger.json +++ b/sqle/docs/swagger.json @@ -3750,11 +3750,11 @@ "ApiKeyAuth": [] } ], - "description": "export audit plan SQL report as CSV", + "description": "export audit plan SQL report as CSV or Excel", "tags": [ "instance_audit_plan" ], - "summary": "导出指定扫描任务的 SQL CSV 列表", + "summary": "导出指定扫描任务的 SQL 列表", "operationId": "getInstanceAuditPlanSQLExportV1", "parameters": [ { @@ -8057,7 +8057,7 @@ "ApiKeyAuth": [] } ], - "description": "export workflow", + "description": "export workflow as CSV or Excel", "tags": [ "workflow" ], @@ -8145,6 +8145,16 @@ "description": "fuzzy matching subject/workflow_id/desc", "name": "fuzzy_keyword", "in": "query" + }, + { + "enum": [ + "csv", + "excel" + ], + "type": "string", + "description": "export format", + "name": "export_format", + "in": "query" } ], "responses": { @@ -11724,7 +11734,7 @@ "ApiKeyAuth": [] } ], - "description": "export sql manage", + "description": "export sql manage as CSV or Excel", "tags": [ "SqlManage" ], @@ -11862,6 +11872,16 @@ "description": "sort order", "name": "sort_order", "in": "query" + }, + { + "enum": [ + "csv", + "excel" + ], + "type": "string", + "description": "export format", + "name": "export_format", + "in": "query" } ], "responses": { @@ -15839,6 +15859,15 @@ "v1.GetAuditPlanSQLExportReqV1": { "type": "object", "properties": { + "export_format": { + "description": "导出格式:csv 或 excel,默认为 excel", + "type": "string", + "enum": [ + "csv", + "excel" + ], + "example": "excel" + }, "filter_list": { "type": "array", "items": { diff --git a/sqle/docs/swagger.yaml b/sqle/docs/swagger.yaml index 02fc42adbd..b5c51a86e8 100644 --- a/sqle/docs/swagger.yaml +++ b/sqle/docs/swagger.yaml @@ -1836,6 +1836,13 @@ definitions: type: object v1.GetAuditPlanSQLExportReqV1: properties: + export_format: + description: 导出格式:csv 或 excel,默认为 excel + enum: + - csv + - excel + example: excel + type: string filter_list: items: $ref: '#/definitions/v1.Filter' @@ -9836,7 +9843,7 @@ paths: - instance_audit_plan /v1/projects/{project_name}/instance_audit_plans/{instance_audit_plan_id}/audit_plans/{audit_plan_id}/sql_export: post: - description: export audit plan SQL report as CSV + description: export audit plan SQL report as CSV or Excel operationId: getInstanceAuditPlanSQLExportV1 parameters: - description: project name @@ -9867,7 +9874,7 @@ paths: type: file security: - ApiKeyAuth: [] - summary: 导出指定扫描任务的 SQL CSV 列表 + summary: 导出指定扫描任务的 SQL 列表 tags: - instance_audit_plan /v1/projects/{project_name}/instance_audit_plans/{instance_audit_plan_id}/audit_plans/{audit_plan_id}/sql_meta: @@ -13233,7 +13240,7 @@ paths: - workflow /v1/projects/{project_name}/workflows/exports: get: - description: export workflow + description: export workflow as CSV or Excel operationId: exportWorkflowV1 parameters: - description: filter subject @@ -13293,6 +13300,13 @@ paths: in: query name: fuzzy_keyword type: string + - description: export format + enum: + - csv + - excel + in: query + name: export_format + type: string responses: "200": description: export workflow @@ -15063,7 +15077,7 @@ paths: - SqlManage /v2/projects/{project_name}/sql_manages/exports: get: - description: export sql manage + description: export sql manage as CSV or Excel operationId: exportSqlManageV2 parameters: - description: project name @@ -15158,6 +15172,13 @@ paths: in: query name: sort_order type: string + - description: export format + enum: + - csv + - excel + in: query + name: export_format + type: string responses: "200": description: export sql manage diff --git a/sqle/utils/excel_builder.go b/sqle/utils/excel_builder.go new file mode 100644 index 0000000000..09841a92a5 --- /dev/null +++ b/sqle/utils/excel_builder.go @@ -0,0 +1,214 @@ +package utils + +import ( + "fmt" + "unicode/utf8" + + "github.com/360EntSecGroup-Skylar/excelize" +) + +// ExcelBuilder 用于构建Excel文件,支持自适应列宽 +type ExcelBuilder struct { + file *excelize.File + sheetName string + rowIndex int + colWidths map[int]float64 // 列索引 -> 最大宽度 +} + +// NewExcelBuilder 创建并返回一个新的ExcelBuilder实例 +// +// 返回: +// +// *ExcelBuilder: 新的ExcelBuilder实例 +// error: 如果创建失败则返回错误 +func NewExcelBuilder() (*ExcelBuilder, error) { + f := excelize.NewFile() + sheetName := "Sheet1" + + // 删除默认的Sheet1,创建新的工作表 + f.NewSheet(sheetName) + + // 删除默认的Sheet1 + f.DeleteSheet("Sheet1") + + return &ExcelBuilder{ + file: f, + sheetName: sheetName, + rowIndex: 1, + colWidths: make(map[int]float64), + }, nil +} + +// WriteHeader 写入Excel文件的表头 +// +// 参数: +// +// header: 表头字符串数组 +// +// 返回: +// +// error: 如果写入失败则返回错误 +func (b *ExcelBuilder) WriteHeader(header []string) error { + // excelize v1使用JSON字符串定义样式 + styleJSON := `{"font":{"bold":true},"fill":{"type":"pattern","color":["#E0E0E0"],"pattern":1}}` + styleID, err := b.file.NewStyle(styleJSON) + if err != nil { + return fmt.Errorf("create header style failed: %v", err) + } + + for col, value := range header { + cellName := getCellName(col+1, b.rowIndex) + + b.file.SetCellValue(b.sheetName, cellName, value) + + // 应用表头样式 + b.file.SetCellStyle(b.sheetName, cellName, cellName, styleID) + + // 更新列宽 + b.updateColumnWidth(col, value) + } + + b.rowIndex++ + return nil +} + +// WriteRow 写入单行数据到Excel文件 +// +// 参数: +// +// row: 字符串数组,代表一条记录 +// +// 返回: +// +// error: 如果写入失败则返回错误 +func (b *ExcelBuilder) WriteRow(row []string) error { + for col, value := range row { + cellName := getCellName(col+1, b.rowIndex) + + // 处理超长字符串 + truncatedValue := TruncateAndMarkForExcelCell(value) + + b.file.SetCellValue(b.sheetName, cellName, truncatedValue) + + // 更新列宽 + b.updateColumnWidth(col, truncatedValue) + } + + b.rowIndex++ + return nil +} + +// WriteRows 写入多行数据到Excel文件 +// +// 参数: +// +// rows: 二维字符串数组,每行代表一条记录 +// +// 返回: +// +// error: 如果写入失败则返回错误 +func (b *ExcelBuilder) WriteRows(rows [][]string) error { + for _, row := range rows { + if err := b.WriteRow(row); err != nil { + return err + } + } + return nil +} + +// updateColumnWidth 更新列的宽度,基于单元格内容 +func (b *ExcelBuilder) updateColumnWidth(col int, value string) { + // 计算字符串宽度(考虑中文字符) + width := calculateStringWidth(value) + + // 添加一些边距(约2个字符宽度) + width += 2 + + // 设置最小宽度为10,最大宽度为100 + if width < 10 { + width = 10 + } else if width > 100 { + width = 100 + } + + // 更新最大宽度 + if currentWidth, exists := b.colWidths[col]; !exists || width > currentWidth { + b.colWidths[col] = width + } +} + +// calculateStringWidth 计算字符串的显示宽度 +// 中文字符按2个字符宽度计算,其他字符按1个字符宽度计算 +func calculateStringWidth(s string) float64 { + var width float64 + for _, r := range s { + if utf8.RuneLen(r) > 1 { + // 中文字符或其他多字节字符,按2个字符宽度计算 + width += 2 + } else { + // ASCII字符,按1个字符宽度计算 + width += 1 + } + } + return width +} + +// SetColumnWidths 设置所有列的宽度为自适应后的宽度 +func (b *ExcelBuilder) SetColumnWidths() error { + for col, width := range b.colWidths { + colName := getColumnName(col + 1) + + b.file.SetColWidth(b.sheetName, colName, colName, width) + } + return nil +} + +// getCellName 将列号和行号转换为Excel单元格名称(如 A1, B2) +func getCellName(col, row int) string { + colName := getColumnName(col) + return fmt.Sprintf("%s%d", colName, row) +} + +// getColumnName 将列号转换为Excel列名(如 1->A, 2->B, 27->AA) +func getColumnName(col int) string { + result := "" + for col > 0 { + col-- + result = string(rune('A'+col%26)) + result + col /= 26 + } + return result +} + +// FlushAndGetBuffer 刷新缓冲区并返回包含Excel内容的字节数组 +// +// 返回: +// +// []byte: 包含Excel文件内容的字节数组 +// error: 如果处理失败则返回错误 +func (b *ExcelBuilder) FlushAndGetBuffer() ([]byte, error) { + // 设置所有列的宽度 + if err := b.SetColumnWidths(); err != nil { + return nil, fmt.Errorf("set column widths failed: %v", err) + } + + // 设置活动工作表 + sheetIndex := b.file.GetSheetIndex(b.sheetName) + if sheetIndex > 0 { + b.file.SetActiveSheet(sheetIndex) + } + + // 写入到缓冲区 + buffer, err := b.file.WriteToBuffer() + if err != nil { + return nil, fmt.Errorf("write to buffer failed: %v", err) + } + + return buffer.Bytes(), nil +} + +// Close 关闭Excel文件并释放资源(excelize v1不需要显式关闭) +func (b *ExcelBuilder) Close() error { + // excelize v1的File结构体没有Close方法,这里不需要做任何操作 + return nil +} diff --git a/sqle/utils/file.go b/sqle/utils/file.go index f4dd0edc99..5fe22435ce 100644 --- a/sqle/utils/file.go +++ b/sqle/utils/file.go @@ -1,9 +1,11 @@ package utils import ( + "fmt" "io" "io/fs" "os" + "time" ) // Grant file owners read and write execution permissions, group and other users read-only permissions @@ -71,3 +73,110 @@ func SaveFile(file io.ReadSeeker, targetPath string) (err error) { } return nil } + +// ExportFormat 导出格式枚举类型 +type ExportFormat string + +const ( + CsvExportFormat ExportFormat = "csv" + ExcelExportFormat ExportFormat = "excel" +) + +// ExportDataResult 导出数据的结果 +type ExportDataResult struct { + Content []byte + ContentType string + FileName string +} + +// ExportDataAsExcel 将数据导出为 Excel 格式 +// header: 表头字符串数组 +// rows: 数据行,二维字符串数组 +// fileNamePrefix: 文件名前缀,会自动添加时间戳和 .xlsx 扩展名 +// prependRows: 可选的前置行,会在表头之前写入(可以为 nil) +func ExportDataAsExcel(header []string, rows [][]string, fileNamePrefix string, prependRows ...[][]string) (*ExportDataResult, error) { + excelBuilder, err := NewExcelBuilder() + if err != nil { + return nil, fmt.Errorf("create excel builder failed: %v", err) + } + defer excelBuilder.Close() + + // 如果有前置行,先写入前置行 + if len(prependRows) > 0 && prependRows[0] != nil { + if err = excelBuilder.WriteRows(prependRows[0]); err != nil { + return nil, fmt.Errorf("write excel prepend rows failed: %v", err) + } + } + + if err = excelBuilder.WriteHeader(header); err != nil { + return nil, fmt.Errorf("write excel header failed: %v", err) + } + if err = excelBuilder.WriteRows(rows); err != nil { + return nil, fmt.Errorf("write excel rows failed: %v", err) + } + + fileBytes, err := excelBuilder.FlushAndGetBuffer() + if err != nil { + return nil, fmt.Errorf("flush excel buffer failed: %v", err) + } + + fileName := fmt.Sprintf("%s_%s.xlsx", fileNamePrefix, time.Now().Format("20060102150405")) + return &ExportDataResult{ + Content: fileBytes, + ContentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + FileName: fileName, + }, nil +} + +// ExportDataAsCSV 将数据导出为 CSV 格式 +// header: 表头字符串数组 +// rows: 数据行,二维字符串数组 +// fileNamePrefix: 文件名前缀,会自动添加时间戳和 .csv 扩展名 +// prependRows: 可选的前置行,会在表头之前写入(可以为 nil) +func ExportDataAsCSV(header []string, rows [][]string, fileNamePrefix string, prependRows ...[][]string) (*ExportDataResult, error) { + csvBuilder := NewCSVBuilder() + + // 如果有前置行,先写入前置行 + if len(prependRows) > 0 && prependRows[0] != nil { + if err := csvBuilder.WriteRows(prependRows[0]); err != nil { + return nil, fmt.Errorf("write csv prepend rows failed: %v", err) + } + } + + if err := csvBuilder.WriteHeader(header); err != nil { + return nil, fmt.Errorf("write csv header failed: %v", err) + } + if err := csvBuilder.WriteRows(rows); err != nil { + return nil, fmt.Errorf("write csv rows failed: %v", err) + } + + fileBytes := csvBuilder.FlushAndGetBuffer().Bytes() + fileName := fmt.Sprintf("%s_%s.csv", fileNamePrefix, time.Now().Format("20060102150405")) + return &ExportDataResult{ + Content: fileBytes, + ContentType: "text/csv", + FileName: fileName, + }, nil +} + +// NormalizeExportFormat 规范化导出格式 +// 如果格式为空,则默认返回 "csv" +func NormalizeExportFormat(format *ExportFormat) ExportFormat { + if format == nil { + return CsvExportFormat + } + return *format +} + +// ExportData 根据导出格式导出数据 +// header: 表头字符串数组 +// rows: 数据行,二维字符串数组 +// fileNamePrefix: 文件名前缀,会自动添加时间戳和扩展名 +// exportFormat: 导出格式(CsvExportFormat 或 ExcelExportFormat) +// prependRows: 可选的前置行,会在表头之前写入(可以为 nil) +func ExportData(header []string, rows [][]string, fileNamePrefix string, exportFormat ExportFormat, prependRows ...[][]string) (*ExportDataResult, error) { + if exportFormat == ExcelExportFormat { + return ExportDataAsExcel(header, rows, fileNamePrefix, prependRows...) + } + return ExportDataAsCSV(header, rows, fileNamePrefix, prependRows...) +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/.gitignore b/vendor/github.com/360EntSecGroup-Skylar/excelize/.gitignore new file mode 100644 index 0000000000..ef972f604b --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/.gitignore @@ -0,0 +1 @@ +test/Test*.xlsx diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/.travis.yml b/vendor/github.com/360EntSecGroup-Skylar/excelize/.travis.yml new file mode 100644 index 0000000000..c2f0f90590 --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/.travis.yml @@ -0,0 +1,26 @@ +language: go + +install: + - go get -d -t -v ./... && go build -v ./... + +go: + - 1.8.x + - 1.9.x + - 1.10.x + - 1.11.x + +os: + - linux + - osx + +env: + matrix: + - GOARCH=amd64 + - GOARCH=386 + +script: + - go vet ./... + - go test ./... -v -coverprofile=coverage.txt -covermode=atomic + +after_success: + - bash <(curl -s https://codecov.io/bash) diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/CODE_OF_CONDUCT.md b/vendor/github.com/360EntSecGroup-Skylar/excelize/CODE_OF_CONDUCT.md new file mode 100644 index 0000000000..a84b47ff95 --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/CODE_OF_CONDUCT.md @@ -0,0 +1,46 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [xuri.me](https://xuri.me). The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/CONTRIBUTING.md b/vendor/github.com/360EntSecGroup-Skylar/excelize/CONTRIBUTING.md new file mode 100644 index 0000000000..f4382ec03a --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/CONTRIBUTING.md @@ -0,0 +1,464 @@ + +# Contributing to excelize + +Want to hack on excelize? Awesome! This page contains information about reporting issues as well as some tips and +guidelines useful to experienced open source contributors. Finally, make sure +you read our [community guidelines](#community-guidelines) before you +start participating. + +## Topics + +* [Reporting Security Issues](#reporting-security-issues) +* [Design and Cleanup Proposals](#design-and-cleanup-proposals) +* [Reporting Issues](#reporting-other-issues) +* [Quick Contribution Tips and Guidelines](#quick-contribution-tips-and-guidelines) +* [Community Guidelines](#community-guidelines) + +## Reporting security issues + +The excelize maintainers take security seriously. If you discover a security +issue, please bring it to their attention right away! + +Please **DO NOT** file a public issue, instead send your report privately to +[xuri.me](https://xuri.me). + +Security reports are greatly appreciated and we will publicly thank you for it. +We currently do not offer a paid security bounty program, but are not +ruling it out in the future. + +## Reporting other issues + +A great way to contribute to the project is to send a detailed report when you +encounter an issue. We always appreciate a well-written, thorough bug report, +and will thank you for it! + +Check that [our issue database](https://github.com/360EntSecGroup-Skylar/excelize/issues) +doesn't already include that problem or suggestion before submitting an issue. +If you find a match, you can use the "subscribe" button to get notified on +updates. Do *not* leave random "+1" or "I have this too" comments, as they +only clutter the discussion, and don't help resolving it. However, if you +have ways to reproduce the issue or have additional information that may help +resolving the issue, please leave a comment. + +When reporting issues, always include the output of `go env`. + +Also include the steps required to reproduce the problem if possible and +applicable. This information will help us review and fix your issue faster. +When sending lengthy log-files, consider posting them as a gist [https://gist.github.com](https://gist.github.com). +Don't forget to remove sensitive data from your logfiles before posting (you can +replace those parts with "REDACTED"). + +## Quick contribution tips and guidelines + +This section gives the experienced contributor some tips and guidelines. + +### Pull requests are always welcome + +Not sure if that typo is worth a pull request? Found a bug and know how to fix +it? Do it! We will appreciate it. Any significant improvement should be +documented as [a GitHub issue](https://github.com/360EntSecGroup-Skylar/excelize/issues) before +anybody starts working on it. + +We are always thrilled to receive pull requests. We do our best to process them +quickly. If your pull request is not accepted on the first try, +don't get discouraged! + +### Design and cleanup proposals + +You can propose new designs for existing excelize features. You can also design +entirely new features. We really appreciate contributors who want to refactor or +otherwise cleanup our project. + +We try hard to keep excelize lean and focused. Excelize can't do everything for +everybody. This means that we might decide against incorporating a new feature. +However, there might be a way to implement that feature *on top of* excelize. + +### Conventions + +Fork the repository and make changes on your fork in a feature branch: + +* If it's a bug fix branch, name it XXXX-something where XXXX is the number of + the issue. +* If it's a feature branch, create an enhancement issue to announce + your intentions, and name it XXXX-something where XXXX is the number of the + issue. + +Submit unit tests for your changes. Go has a great test framework built in; use +it! Take a look at existing tests for inspiration. Run the full test on your branch before +submitting a pull request. + +Update the documentation when creating or modifying features. Test your +documentation changes for clarity, concision, and correctness, as well as a +clean documentation build. + +Write clean code. Universally formatted code promotes ease of writing, reading, +and maintenance. Always run `gofmt -s -w file.go` on each changed file before +committing your changes. Most editors have plug-ins that do this automatically. + +Pull request descriptions should be as clear as possible and include a reference +to all the issues that they address. + +### Successful Changes + +Before contributing large or high impact changes, make the effort to coordinate +with the maintainers of the project before submitting a pull request. This +prevents you from doing extra work that may or may not be merged. + +Large PRs that are just submitted without any prior communication are unlikely +to be successful. + +While pull requests are the methodology for submitting changes to code, changes +are much more likely to be accepted if they are accompanied by additional +engineering work. While we don't define this explicitly, most of these goals +are accomplished through communication of the design goals and subsequent +solutions. Often times, it helps to first state the problem before presenting +solutions. + +Typically, the best methods of accomplishing this are to submit an issue, +stating the problem. This issue can include a problem statement and a +checklist with requirements. If solutions are proposed, alternatives should be +listed and eliminated. Even if the criteria for elimination of a solution is +frivolous, say so. + +Larger changes typically work best with design documents. These are focused on +providing context to the design at the time the feature was conceived and can +inform future documentation contributions. + +### Commit Messages + +Commit messages must start with a capitalized and short summary +written in the imperative, followed by an optional, more detailed explanatory +text which is separated from the summary by an empty line. + +Commit messages should follow best practices, including explaining the context +of the problem and how it was solved, including in caveats or follow up changes +required. They should tell the story of the change and provide readers +understanding of what led to it. + +In practice, the best approach to maintaining a nice commit message is to +leverage a `git add -p` and `git commit --amend` to formulate a solid +changeset. This allows one to piece together a change, as information becomes +available. + +If you squash a series of commits, don't just submit that. Re-write the commit +message, as if the series of commits was a single stroke of brilliance. + +That said, there is no requirement to have a single commit for a PR, as long as +each commit tells the story. For example, if there is a feature that requires a +package, it might make sense to have the package in a separate commit then have +a subsequent commit that uses it. + +Remember, you're telling part of the story with the commit message. Don't make +your chapter weird. + +### Review + +Code review comments may be added to your pull request. Discuss, then make the +suggested modifications and push additional commits to your feature branch. Post +a comment after pushing. New commits show up in the pull request automatically, +but the reviewers are notified only when you comment. + +Pull requests must be cleanly rebased on top of master without multiple branches +mixed into the PR. + +**Git tip**: If your PR no longer merges cleanly, use `rebase master` in your +feature branch to update your pull request rather than `merge master`. + +Before you make a pull request, squash your commits into logical units of work +using `git rebase -i` and `git push -f`. A logical unit of work is a consistent +set of patches that should be reviewed together: for example, upgrading the +version of a vendored dependency and taking advantage of its now available new +feature constitute two separate units of work. Implementing a new function and +calling it in another file constitute a single logical unit of work. The very +high majority of submissions should have a single commit, so if in doubt: squash +down to one. + +After every commit, make sure the test passes. Include documentation +changes in the same pull request so that a revert would remove all traces of +the feature or fix. + +Include an issue reference like `Closes #XXXX` or `Fixes #XXXX` in commits that +close an issue. Including references automatically closes the issue on a merge. + +Please see the [Coding Style](#coding-style) for further guidelines. + +### Merge approval + +The excelize maintainers use LGTM (Looks Good To Me) in comments on the code review to +indicate acceptance. + +### Sign your work + +The sign-off is a simple line at the end of the explanation for the patch. Your +signature certifies that you wrote the patch or otherwise have the right to pass +it on as an open-source patch. The rules are pretty simple: if you can certify +the below (from [developercertificate.org](http://developercertificate.org/)): + +```text +Developer Certificate of Origin +Version 1.1 + +Copyright (C) 2004, 2006 The Linux Foundation and its contributors. +1 Letterman Drive +Suite D4700 +San Francisco, CA, 94129 + +Everyone is permitted to copy and distribute verbatim copies of this +license document, but changing it is not allowed. + +Developer's Certificate of Origin 1.1 + +By making a contribution to this project, I certify that: + +(a) The contribution was created in whole or in part by me and I + have the right to submit it under the open source license + indicated in the file; or + +(b) The contribution is based upon previous work that, to the best + of my knowledge, is covered under an appropriate open source + license and I have the right under that license to submit that + work with modifications, whether created in whole or in part + by me, under the same open source license (unless I am + permitted to submit under a different license), as indicated + in the file; or + +(c) The contribution was provided directly to me by some other + person who certified (a), (b) or (c) and I have not modified + it. + +(d) I understand and agree that this project and the contribution + are public and that a record of the contribution (including all + personal information I submit with it, including my sign-off) is + maintained indefinitely and may be redistributed consistent with + this project or the open source license(s) involved. +``` + +Then you just add a line to every git commit message: + + Signed-off-by: Ri Xu https://xuri.me + +Use your real name (sorry, no pseudonyms or anonymous contributions.) + +If you set your `user.name` and `user.email` git configs, you can sign your +commit automatically with `git commit -s`. + +### How can I become a maintainer + +First, all maintainers have 3 things + +* They share responsibility in the project's success. +* They have made a long-term, recurring time investment to improve the project. +* They spend that time doing whatever needs to be done, not necessarily what + is the most interesting or fun. + +Maintainers are often under-appreciated, because their work is harder to appreciate. +It's easy to appreciate a really cool and technically advanced feature. It's harder +to appreciate the absence of bugs, the slow but steady improvement in stability, +or the reliability of a release process. But those things distinguish a good +project from a great one. + +Don't forget: being a maintainer is a time investment. Make sure you +will have time to make yourself available. You don't have to be a +maintainer to make a difference on the project! + +If you want to become a meintainer, contact [xuri.me](https://xuri.me) and given a introduction of you. + +## Community guidelines + +We want to keep the community awesome, growing and collaborative. We need +your help to keep it that way. To help with this we've come up with some general +guidelines for the community as a whole: + +* Be nice: Be courteous, respectful and polite to fellow community members: + no regional, racial, gender, or other abuse will be tolerated. We like + nice people way better than mean ones! + +* Encourage diversity and participation: Make everyone in our community feel + welcome, regardless of their background and the extent of their + contributions, and do everything possible to encourage participation in + our community. + +* Keep it legal: Basically, don't get us in trouble. Share only content that + you own, do not share private or sensitive information, and don't break + the law. + +* Stay on topic: Make sure that you are posting to the correct channel and + avoid off-topic discussions. Remember when you update an issue or respond + to an email you are potentially sending to a large number of people. Please + consider this before you update. Also remember that nobody likes spam. + +* Don't send email to the maintainers: There's no need to send email to the + maintainers to ask them to investigate an issue or to take a look at a + pull request. Instead of sending an email, GitHub mentions should be + used to ping maintainers to review a pull request, a proposal or an + issue. + +### Guideline violations — 3 strikes method + +The point of this section is not to find opportunities to punish people, but we +do need a fair way to deal with people who are making our community suck. + +1. First occurrence: We'll give you a friendly, but public reminder that the + behavior is inappropriate according to our guidelines. + +2. Second occurrence: We will send you a private message with a warning that + any additional violations will result in removal from the community. + +3. Third occurrence: Depending on the violation, we may need to delete or ban + your account. + +**Notes:** + +* Obvious spammers are banned on first occurrence. If we don't do this, we'll + have spam all over the place. + +* Violations are forgiven after 6 months of good behavior, and we won't hold a + grudge. + +* People who commit minor infractions will get some education, rather than + hammering them in the 3 strikes process. + +* The rules apply equally to everyone in the community, no matter how much + you've contributed. + +* Extreme violations of a threatening, abusive, destructive or illegal nature + will be addressed immediately and are not subject to 3 strikes or forgiveness. + +* Contact [xuri.me](https://xuri.me) to report abuse or appeal violations. In the case of + appeals, we know that mistakes happen, and we'll work with you to come up with a + fair solution if there has been a misunderstanding. + +## Coding Style + +Unless explicitly stated, we follow all coding guidelines from the Go +community. While some of these standards may seem arbitrary, they somehow seem +to result in a solid, consistent codebase. + +It is possible that the code base does not currently comply with these +guidelines. We are not looking for a massive PR that fixes this, since that +goes against the spirit of the guidelines. All new contributions should make a +best effort to clean up and make the code base better than they left it. +Obviously, apply your best judgement. Remember, the goal here is to make the +code base easier for humans to navigate and understand. Always keep that in +mind when nudging others to comply. + +The rules: + +1. All code should be formatted with `gofmt -s`. +2. All code should pass the default levels of + [`golint`](https://github.com/golang/lint). +3. All code should follow the guidelines covered in [Effective + Go](http://golang.org/doc/effective_go.html) and [Go Code Review + Comments](https://github.com/golang/go/wiki/CodeReviewComments). +4. Comment the code. Tell us the why, the history and the context. +5. Document _all_ declarations and methods, even private ones. Declare + expectations, caveats and anything else that may be important. If a type + gets exported, having the comments already there will ensure it's ready. +6. Variable name length should be proportional to its context and no longer. + `noCommaALongVariableNameLikeThisIsNotMoreClearWhenASimpleCommentWouldDo`. + In practice, short methods will have short variable names and globals will + have longer names. +7. No underscores in package names. If you need a compound name, step back, + and re-examine why you need a compound name. If you still think you need a + compound name, lose the underscore. +8. No utils or helpers packages. If a function is not general enough to + warrant its own package, it has not been written generally enough to be a + part of a util package. Just leave it unexported and well-documented. +9. All tests should run with `go test` and outside tooling should not be + required. No, we don't need another unit testing framework. Assertion + packages are acceptable if they provide _real_ incremental value. +10. Even though we call these "rules" above, they are actually just + guidelines. Since you've read all the rules, you now know that. + +If you are having trouble getting into the mood of idiomatic Go, we recommend +reading through [Effective Go](https://golang.org/doc/effective_go.html). The +[Go Blog](https://blog.golang.org) is also a great resource. Drinking the +kool-aid is a lot easier than going thirsty. + +## Code Review Comments and Effective Go Guidelines +[CodeLingo](https://codelingo.io) automatically checks every pull request against the following guidelines from [Effective Go](https://golang.org/doc/effective_go.html) and [Code Review Comments](https://github.com/golang/go/wiki/CodeReviewComments). + + +### Package Comment +Every package should have a package comment, a block comment preceding the package clause. +For multi-file packages, the package comment only needs to be present in one file, and any one will do. +The package comment should introduce the package and provide information relevant to the package as a +whole. It will appear first on the godoc page and should set up the detailed documentation that follows. + + +### Single Method Interface Name +By convention, one-method interfaces are named by the method name plus an -er suffix +or similar modification to construct an agent noun: Reader, Writer, Formatter, CloseNotifier etc. + +There are a number of such names and it's productive to honor them and the function names they capture. +Read, Write, Close, Flush, String and so on have canonical signatures and meanings. To avoid confusion, +don't give your method one of those names unless it has the same signature and meaning. Conversely, +if your type implements a method with the same meaning as a method on a well-known type, give it the +same name and signature; call your string-converter method String not ToString. + + +### Avoid Annotations in Comments +Comments do not need extra formatting such as banners of stars. The generated output +may not even be presented in a fixed-width font, so don't depend on spacing for alignment—godoc, +like gofmt, takes care of that. The comments are uninterpreted plain text, so HTML and other +annotations such as _this_ will reproduce verbatim and should not be used. One adjustment godoc +does do is to display indented text in a fixed-width font, suitable for program snippets. +The package comment for the fmt package uses this to good effect. + + +### Comment First Word as Subject +Doc comments work best as complete sentences, which allow a wide variety of automated presentations. +The first sentence should be a one-sentence summary that starts with the name being declared. + + +### Good Package Name +It's helpful if everyone using the package can use the same name +to refer to its contents, which implies that the package name should +be good: short, concise, evocative. By convention, packages are +given lower case, single-word names; there should be no need for +underscores or mixedCaps. Err on the side of brevity, since everyone +using your package will be typing that name. And don't worry about +collisions a priori. The package name is only the default name for +imports; it need not be unique across all source code, and in the +rare case of a collision the importing package can choose a different +name to use locally. In any case, confusion is rare because the file +name in the import determines just which package is being used. + + +### Avoid Renaming Imports +Avoid renaming imports except to avoid a name collision; good package names +should not require renaming. In the event of collision, prefer to rename the +most local or project-specific import. + + +### Context as First Argument +Values of the context.Context type carry security credentials, tracing information, +deadlines, and cancellation signals across API and process boundaries. Go programs +pass Contexts explicitly along the entire function call chain from incoming RPCs +and HTTP requests to outgoing requests. + +Most functions that use a Context should accept it as their first parameter. + + +### Do Not Discard Errors +Do not discard errors using _ variables. If a function returns an error, +check it to make sure the function succeeded. Handle the error, return it, or, +in truly exceptional situations, panic. + + +### Go Error Format +Error strings should not be capitalized (unless beginning with proper nouns +or acronyms) or end with punctuation, since they are usually printed following +other context. That is, use fmt.Errorf("something bad") not fmt.Errorf("Something bad"), +so that log.Printf("Reading %s: %v", filename, err) formats without a spurious +capital letter mid-message. This does not apply to logging, which is implicitly +line-oriented and not combined inside other messages. + + +### Use Crypto Rand +Do not use package math/rand to generate keys, even +throwaway ones. Unseeded, the generator is completely predictable. +Seeded with time.Nanoseconds(), there are just a few bits of entropy. +Instead, use crypto/rand's Reader, and if you need text, print to +hexadecimal or base64 + diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/CONTRIBUTING_TEMPLATE.md b/vendor/github.com/360EntSecGroup-Skylar/excelize/CONTRIBUTING_TEMPLATE.md new file mode 100644 index 0000000000..389f2433a2 --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/CONTRIBUTING_TEMPLATE.md @@ -0,0 +1,384 @@ + +# Contributing to excelize + +Want to hack on excelize? Awesome! This page contains information about reporting issues as well as some tips and +guidelines useful to experienced open source contributors. Finally, make sure +you read our [community guidelines](#community-guidelines) before you +start participating. + +## Topics + +* [Reporting Security Issues](#reporting-security-issues) +* [Design and Cleanup Proposals](#design-and-cleanup-proposals) +* [Reporting Issues](#reporting-other-issues) +* [Quick Contribution Tips and Guidelines](#quick-contribution-tips-and-guidelines) +* [Community Guidelines](#community-guidelines) + +## Reporting security issues + +The excelize maintainers take security seriously. If you discover a security +issue, please bring it to their attention right away! + +Please **DO NOT** file a public issue, instead send your report privately to +[xuri.me](https://xuri.me). + +Security reports are greatly appreciated and we will publicly thank you for it. +We currently do not offer a paid security bounty program, but are not +ruling it out in the future. + +## Reporting other issues + +A great way to contribute to the project is to send a detailed report when you +encounter an issue. We always appreciate a well-written, thorough bug report, +and will thank you for it! + +Check that [our issue database](https://github.com/360EntSecGroup-Skylar/excelize/issues) +doesn't already include that problem or suggestion before submitting an issue. +If you find a match, you can use the "subscribe" button to get notified on +updates. Do *not* leave random "+1" or "I have this too" comments, as they +only clutter the discussion, and don't help resolving it. However, if you +have ways to reproduce the issue or have additional information that may help +resolving the issue, please leave a comment. + +When reporting issues, always include the output of `go env`. + +Also include the steps required to reproduce the problem if possible and +applicable. This information will help us review and fix your issue faster. +When sending lengthy log-files, consider posting them as a gist [https://gist.github.com](https://gist.github.com). +Don't forget to remove sensitive data from your logfiles before posting (you can +replace those parts with "REDACTED"). + +## Quick contribution tips and guidelines + +This section gives the experienced contributor some tips and guidelines. + +### Pull requests are always welcome + +Not sure if that typo is worth a pull request? Found a bug and know how to fix +it? Do it! We will appreciate it. Any significant improvement should be +documented as [a GitHub issue](https://github.com/360EntSecGroup-Skylar/excelize/issues) before +anybody starts working on it. + +We are always thrilled to receive pull requests. We do our best to process them +quickly. If your pull request is not accepted on the first try, +don't get discouraged! + +### Design and cleanup proposals + +You can propose new designs for existing excelize features. You can also design +entirely new features. We really appreciate contributors who want to refactor or +otherwise cleanup our project. + +We try hard to keep excelize lean and focused. Excelize can't do everything for +everybody. This means that we might decide against incorporating a new feature. +However, there might be a way to implement that feature *on top of* excelize. + +### Conventions + +Fork the repository and make changes on your fork in a feature branch: + +* If it's a bug fix branch, name it XXXX-something where XXXX is the number of + the issue. +* If it's a feature branch, create an enhancement issue to announce + your intentions, and name it XXXX-something where XXXX is the number of the + issue. + +Submit unit tests for your changes. Go has a great test framework built in; use +it! Take a look at existing tests for inspiration. Run the full test on your branch before +submitting a pull request. + +Update the documentation when creating or modifying features. Test your +documentation changes for clarity, concision, and correctness, as well as a +clean documentation build. + +Write clean code. Universally formatted code promotes ease of writing, reading, +and maintenance. Always run `gofmt -s -w file.go` on each changed file before +committing your changes. Most editors have plug-ins that do this automatically. + +Pull request descriptions should be as clear as possible and include a reference +to all the issues that they address. + +### Successful Changes + +Before contributing large or high impact changes, make the effort to coordinate +with the maintainers of the project before submitting a pull request. This +prevents you from doing extra work that may or may not be merged. + +Large PRs that are just submitted without any prior communication are unlikely +to be successful. + +While pull requests are the methodology for submitting changes to code, changes +are much more likely to be accepted if they are accompanied by additional +engineering work. While we don't define this explicitly, most of these goals +are accomplished through communication of the design goals and subsequent +solutions. Often times, it helps to first state the problem before presenting +solutions. + +Typically, the best methods of accomplishing this are to submit an issue, +stating the problem. This issue can include a problem statement and a +checklist with requirements. If solutions are proposed, alternatives should be +listed and eliminated. Even if the criteria for elimination of a solution is +frivolous, say so. + +Larger changes typically work best with design documents. These are focused on +providing context to the design at the time the feature was conceived and can +inform future documentation contributions. + +### Commit Messages + +Commit messages must start with a capitalized and short summary +written in the imperative, followed by an optional, more detailed explanatory +text which is separated from the summary by an empty line. + +Commit messages should follow best practices, including explaining the context +of the problem and how it was solved, including in caveats or follow up changes +required. They should tell the story of the change and provide readers +understanding of what led to it. + +In practice, the best approach to maintaining a nice commit message is to +leverage a `git add -p` and `git commit --amend` to formulate a solid +changeset. This allows one to piece together a change, as information becomes +available. + +If you squash a series of commits, don't just submit that. Re-write the commit +message, as if the series of commits was a single stroke of brilliance. + +That said, there is no requirement to have a single commit for a PR, as long as +each commit tells the story. For example, if there is a feature that requires a +package, it might make sense to have the package in a separate commit then have +a subsequent commit that uses it. + +Remember, you're telling part of the story with the commit message. Don't make +your chapter weird. + +### Review + +Code review comments may be added to your pull request. Discuss, then make the +suggested modifications and push additional commits to your feature branch. Post +a comment after pushing. New commits show up in the pull request automatically, +but the reviewers are notified only when you comment. + +Pull requests must be cleanly rebased on top of master without multiple branches +mixed into the PR. + +**Git tip**: If your PR no longer merges cleanly, use `rebase master` in your +feature branch to update your pull request rather than `merge master`. + +Before you make a pull request, squash your commits into logical units of work +using `git rebase -i` and `git push -f`. A logical unit of work is a consistent +set of patches that should be reviewed together: for example, upgrading the +version of a vendored dependency and taking advantage of its now available new +feature constitute two separate units of work. Implementing a new function and +calling it in another file constitute a single logical unit of work. The very +high majority of submissions should have a single commit, so if in doubt: squash +down to one. + +After every commit, make sure the test passes. Include documentation +changes in the same pull request so that a revert would remove all traces of +the feature or fix. + +Include an issue reference like `Closes #XXXX` or `Fixes #XXXX` in commits that +close an issue. Including references automatically closes the issue on a merge. + +Please see the [Coding Style](#coding-style) for further guidelines. + +### Merge approval + +The excelize maintainers use LGTM (Looks Good To Me) in comments on the code review to +indicate acceptance. + +### Sign your work + +The sign-off is a simple line at the end of the explanation for the patch. Your +signature certifies that you wrote the patch or otherwise have the right to pass +it on as an open-source patch. The rules are pretty simple: if you can certify +the below (from [developercertificate.org](http://developercertificate.org/)): + +```text +Developer Certificate of Origin +Version 1.1 + +Copyright (C) 2004, 2006 The Linux Foundation and its contributors. +1 Letterman Drive +Suite D4700 +San Francisco, CA, 94129 + +Everyone is permitted to copy and distribute verbatim copies of this +license document, but changing it is not allowed. + +Developer's Certificate of Origin 1.1 + +By making a contribution to this project, I certify that: + +(a) The contribution was created in whole or in part by me and I + have the right to submit it under the open source license + indicated in the file; or + +(b) The contribution is based upon previous work that, to the best + of my knowledge, is covered under an appropriate open source + license and I have the right under that license to submit that + work with modifications, whether created in whole or in part + by me, under the same open source license (unless I am + permitted to submit under a different license), as indicated + in the file; or + +(c) The contribution was provided directly to me by some other + person who certified (a), (b) or (c) and I have not modified + it. + +(d) I understand and agree that this project and the contribution + are public and that a record of the contribution (including all + personal information I submit with it, including my sign-off) is + maintained indefinitely and may be redistributed consistent with + this project or the open source license(s) involved. +``` + +Then you just add a line to every git commit message: + + Signed-off-by: Ri Xu https://xuri.me + +Use your real name (sorry, no pseudonyms or anonymous contributions.) + +If you set your `user.name` and `user.email` git configs, you can sign your +commit automatically with `git commit -s`. + +### How can I become a maintainer + +First, all maintainers have 3 things + +* They share responsibility in the project's success. +* They have made a long-term, recurring time investment to improve the project. +* They spend that time doing whatever needs to be done, not necessarily what + is the most interesting or fun. + +Maintainers are often under-appreciated, because their work is harder to appreciate. +It's easy to appreciate a really cool and technically advanced feature. It's harder +to appreciate the absence of bugs, the slow but steady improvement in stability, +or the reliability of a release process. But those things distinguish a good +project from a great one. + +Don't forget: being a maintainer is a time investment. Make sure you +will have time to make yourself available. You don't have to be a +maintainer to make a difference on the project! + +If you want to become a meintainer, contact [xuri.me](https://xuri.me) and given a introduction of you. + +## Community guidelines + +We want to keep the community awesome, growing and collaborative. We need +your help to keep it that way. To help with this we've come up with some general +guidelines for the community as a whole: + +* Be nice: Be courteous, respectful and polite to fellow community members: + no regional, racial, gender, or other abuse will be tolerated. We like + nice people way better than mean ones! + +* Encourage diversity and participation: Make everyone in our community feel + welcome, regardless of their background and the extent of their + contributions, and do everything possible to encourage participation in + our community. + +* Keep it legal: Basically, don't get us in trouble. Share only content that + you own, do not share private or sensitive information, and don't break + the law. + +* Stay on topic: Make sure that you are posting to the correct channel and + avoid off-topic discussions. Remember when you update an issue or respond + to an email you are potentially sending to a large number of people. Please + consider this before you update. Also remember that nobody likes spam. + +* Don't send email to the maintainers: There's no need to send email to the + maintainers to ask them to investigate an issue or to take a look at a + pull request. Instead of sending an email, GitHub mentions should be + used to ping maintainers to review a pull request, a proposal or an + issue. + +### Guideline violations — 3 strikes method + +The point of this section is not to find opportunities to punish people, but we +do need a fair way to deal with people who are making our community suck. + +1. First occurrence: We'll give you a friendly, but public reminder that the + behavior is inappropriate according to our guidelines. + +2. Second occurrence: We will send you a private message with a warning that + any additional violations will result in removal from the community. + +3. Third occurrence: Depending on the violation, we may need to delete or ban + your account. + +**Notes:** + +* Obvious spammers are banned on first occurrence. If we don't do this, we'll + have spam all over the place. + +* Violations are forgiven after 6 months of good behavior, and we won't hold a + grudge. + +* People who commit minor infractions will get some education, rather than + hammering them in the 3 strikes process. + +* The rules apply equally to everyone in the community, no matter how much + you've contributed. + +* Extreme violations of a threatening, abusive, destructive or illegal nature + will be addressed immediately and are not subject to 3 strikes or forgiveness. + +* Contact [xuri.me](https://xuri.me) to report abuse or appeal violations. In the case of + appeals, we know that mistakes happen, and we'll work with you to come up with a + fair solution if there has been a misunderstanding. + +## Coding Style + +Unless explicitly stated, we follow all coding guidelines from the Go +community. While some of these standards may seem arbitrary, they somehow seem +to result in a solid, consistent codebase. + +It is possible that the code base does not currently comply with these +guidelines. We are not looking for a massive PR that fixes this, since that +goes against the spirit of the guidelines. All new contributions should make a +best effort to clean up and make the code base better than they left it. +Obviously, apply your best judgement. Remember, the goal here is to make the +code base easier for humans to navigate and understand. Always keep that in +mind when nudging others to comply. + +The rules: + +1. All code should be formatted with `gofmt -s`. +2. All code should pass the default levels of + [`golint`](https://github.com/golang/lint). +3. All code should follow the guidelines covered in [Effective + Go](http://golang.org/doc/effective_go.html) and [Go Code Review + Comments](https://github.com/golang/go/wiki/CodeReviewComments). +4. Comment the code. Tell us the why, the history and the context. +5. Document _all_ declarations and methods, even private ones. Declare + expectations, caveats and anything else that may be important. If a type + gets exported, having the comments already there will ensure it's ready. +6. Variable name length should be proportional to its context and no longer. + `noCommaALongVariableNameLikeThisIsNotMoreClearWhenASimpleCommentWouldDo`. + In practice, short methods will have short variable names and globals will + have longer names. +7. No underscores in package names. If you need a compound name, step back, + and re-examine why you need a compound name. If you still think you need a + compound name, lose the underscore. +8. No utils or helpers packages. If a function is not general enough to + warrant its own package, it has not been written generally enough to be a + part of a util package. Just leave it unexported and well-documented. +9. All tests should run with `go test` and outside tooling should not be + required. No, we don't need another unit testing framework. Assertion + packages are acceptable if they provide _real_ incremental value. +10. Even though we call these "rules" above, they are actually just + guidelines. Since you've read all the rules, you now know that. + +If you are having trouble getting into the mood of idiomatic Go, we recommend +reading through [Effective Go](https://golang.org/doc/effective_go.html). The +[Go Blog](https://blog.golang.org) is also a great resource. Drinking the +kool-aid is a lot easier than going thirsty. + +## Code Review Comments and Effective Go Guidelines +[CodeLingo](https://codelingo.io) automatically checks every pull request against the following guidelines from [Effective Go](https://golang.org/doc/effective_go.html) and [Code Review Comments](https://github.com/golang/go/wiki/CodeReviewComments). + +{{range .}} +### {{.title}} +{{.body}} +{{end}} \ No newline at end of file diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/LICENSE b/vendor/github.com/360EntSecGroup-Skylar/excelize/LICENSE new file mode 100644 index 0000000000..1ece21dec2 --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2016 - 2019 360 Enterprise Security Group, Endpoint Security, +inc. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of Excelize nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/PULL_REQUEST_TEMPLATE.md b/vendor/github.com/360EntSecGroup-Skylar/excelize/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000000..d2ac755e96 --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,45 @@ +# PR Details + + + +## Description + + + +## Related Issue + + + + + + +## Motivation and Context + + + +## How Has This Been Tested + + + + + +## Types of changes + + + +- [ ] Docs change / refactoring / dependency upgrade +- [ ] Bug fix (non-breaking change which fixes an issue) +- [ ] New feature (non-breaking change which adds functionality) +- [ ] Breaking change (fix or feature that would cause existing functionality to change) + +## Checklist + + + + +- [ ] My code follows the code style of this project. +- [ ] My change requires a change to the documentation. +- [ ] I have updated the documentation accordingly. +- [ ] I have read the **CONTRIBUTING** document. +- [ ] I have added tests to cover my changes. +- [ ] All new and existing tests passed. diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/README.md b/vendor/github.com/360EntSecGroup-Skylar/excelize/README.md new file mode 100644 index 0000000000..56f79e0a0f --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/README.md @@ -0,0 +1,179 @@ +

Excelize logo

+ +

+ Build Status + Code Coverage + Go Report Card + GoDoc + Licenses + Donate +

+ +# Excelize + +## Introduction + +Excelize is a library written in pure Go and providing a set of functions that allow you to write to and read from XLSX files. Support reads and writes XLSX file generated by Microsoft Excel™ 2007 and later. Support save file without losing original charts of XLSX. This library needs Go version 1.8 or later. The full API docs can be seen using go's built-in documentation tool, or online at [godoc.org](https://godoc.org/github.com/360EntSecGroup-Skylar/excelize) and [docs reference](https://xuri.me/excelize/). + +## Basic Usage + +### Installation + +```go +go get github.com/360EntSecGroup-Skylar/excelize +``` + +### Create XLSX file + +Here is a minimal example usage that will create XLSX file. + +```go +package main + +import ( + "fmt" + + "github.com/360EntSecGroup-Skylar/excelize" +) + +func main() { + xlsx := excelize.NewFile() + // Create a new sheet. + index := xlsx.NewSheet("Sheet2") + // Set value of a cell. + xlsx.SetCellValue("Sheet2", "A2", "Hello world.") + xlsx.SetCellValue("Sheet1", "B2", 100) + // Set active sheet of the workbook. + xlsx.SetActiveSheet(index) + // Save xlsx file by the given path. + err := xlsx.SaveAs("./Book1.xlsx") + if err != nil { + fmt.Println(err) + } +} +``` + +### Reading XLSX file + +The following constitutes the bare to read a XLSX document. + +```go +package main + +import ( + "fmt" + + "github.com/360EntSecGroup-Skylar/excelize" +) + +func main() { + xlsx, err := excelize.OpenFile("./Book1.xlsx") + if err != nil { + fmt.Println(err) + return + } + // Get value from cell by given worksheet name and axis. + cell := xlsx.GetCellValue("Sheet1", "B2") + fmt.Println(cell) + // Get all the rows in the Sheet1. + rows := xlsx.GetRows("Sheet1") + for _, row := range rows { + for _, colCell := range row { + fmt.Print(colCell, "\t") + } + fmt.Println() + } +} +``` + +### Add chart to XLSX file + +With Excelize chart generation and management is as easy as a few lines of code. You can build charts based off data in your worksheet or generate charts without any data in your worksheet at all. + +

Excelize

+ +```go +package main + +import ( + "fmt" + + "github.com/360EntSecGroup-Skylar/excelize" +) + +func main() { + categories := map[string]string{"A2": "Small", "A3": "Normal", "A4": "Large", "B1": "Apple", "C1": "Orange", "D1": "Pear"} + values := map[string]int{"B2": 2, "C2": 3, "D2": 3, "B3": 5, "C3": 2, "D3": 4, "B4": 6, "C4": 7, "D4": 8} + xlsx := excelize.NewFile() + for k, v := range categories { + xlsx.SetCellValue("Sheet1", k, v) + } + for k, v := range values { + xlsx.SetCellValue("Sheet1", k, v) + } + xlsx.AddChart("Sheet1", "E1", `{"type":"col3DClustered","series":[{"name":"Sheet1!$A$2","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$2:$D$2"},{"name":"Sheet1!$A$3","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$3:$D$3"},{"name":"Sheet1!$A$4","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"}],"title":{"name":"Fruit 3D Clustered Column Chart"}}`) + // Save xlsx file by the given path. + err := xlsx.SaveAs("./Book1.xlsx") + if err != nil { + fmt.Println(err) + } +} + +``` + +### Add picture to XLSX file + +```go +package main + +import ( + "fmt" + _ "image/gif" + _ "image/jpeg" + _ "image/png" + + "github.com/360EntSecGroup-Skylar/excelize" +) + +func main() { + xlsx, err := excelize.OpenFile("./Book1.xlsx") + if err != nil { + fmt.Println(err) + return + } + // Insert a picture. + err = xlsx.AddPicture("Sheet1", "A2", "./image1.png", "") + if err != nil { + fmt.Println(err) + } + // Insert a picture to worksheet with scaling. + err = xlsx.AddPicture("Sheet1", "D2", "./image2.jpg", `{"x_scale": 0.5, "y_scale": 0.5}`) + if err != nil { + fmt.Println(err) + } + // Insert a picture offset in the cell with printing support. + err = xlsx.AddPicture("Sheet1", "H2", "./image3.gif", `{"x_offset": 15, "y_offset": 10, "print_obj": true, "lock_aspect_ratio": false, "locked": false}`) + if err != nil { + fmt.Println(err) + } + // Save the xlsx file with the origin path. + err = xlsx.Save() + if err != nil { + fmt.Println(err) + } +} +``` + +## Contributing + +Contributions are welcome! Open a pull request to fix a bug, or open an issue to discuss a new feature or change. XML is compliant with [part 1 of the 5th edition of the ECMA-376 Standard for Office Open XML](http://www.ecma-international.org/publications/standards/Ecma-376.htm). + +## Credits + +Some struct of XML originally by [tealeg/xlsx](https://github.com/tealeg/xlsx). + +## Licenses + +This program is under the terms of the BSD 3-Clause License. See [https://opensource.org/licenses/BSD-3-Clause](https://opensource.org/licenses/BSD-3-Clause). + +[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2F360EntSecGroup-Skylar%2Fexcelize.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2F360EntSecGroup-Skylar%2Fexcelize?ref=badge_large) diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/README_zh.md b/vendor/github.com/360EntSecGroup-Skylar/excelize/README_zh.md new file mode 100644 index 0000000000..6fbbb00b17 --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/README_zh.md @@ -0,0 +1,179 @@ +

Excelize logo

+ +

+ Build Status + Code Coverage + Go Report Card + GoDoc + Licenses + Donate +

+ +# Excelize + +## 简介 + +Excelize 是 Go 语言编写的用于操作 Office Excel 文档类库,基于 ECMA-376 Office OpenXML 标准。可以使用它来读取、写入由 Microsoft Excel™ 2007 及以上版本创建的 XLSX 文档。相比较其他的开源类库,Excelize 支持写入原本带有图片(表)、透视表和切片器等复杂样式的文档,还支持向 Excel 文档中插入图片与图表,并且在保存后不会丢失文档原有样式,可以应用于各类报表系统中。使用本类库要求使用的 Go 语言为 1.8 或更高版本,完整的 API 使用文档请访问 [godoc.org](https://godoc.org/github.com/360EntSecGroup-Skylar/excelize) 或查看 [参考文档](https://xuri.me/excelize/)。 + +## 快速上手 + +### 安装 + +```go +go get github.com/360EntSecGroup-Skylar/excelize +``` + +### 创建 Excel 文档 + +下面是一个创建 Excel 文档的简单例子: + +```go +package main + +import ( + "fmt" + + "github.com/360EntSecGroup-Skylar/excelize" +) + +func main() { + xlsx := excelize.NewFile() + // 创建一个工作表 + index := xlsx.NewSheet("Sheet2") + // 设置单元格的值 + xlsx.SetCellValue("Sheet2", "A2", "Hello world.") + xlsx.SetCellValue("Sheet1", "B2", 100) + // 设置工作簿的默认工作表 + xlsx.SetActiveSheet(index) + // 根据指定路径保存文件 + err := xlsx.SaveAs("./Book1.xlsx") + if err != nil { + fmt.Println(err) + } +} +``` + +### 读取 Excel 文档 + +下面是读取 Excel 文档的例子: + +```go +package main + +import ( + "fmt" + + "github.com/360EntSecGroup-Skylar/excelize" +) + +func main() { + xlsx, err := excelize.OpenFile("./Book1.xlsx") + if err != nil { + fmt.Println(err) + return + } + // 获取工作表中指定单元格的值 + cell := xlsx.GetCellValue("Sheet1", "B2") + fmt.Println(cell) + // 获取 Sheet1 上所有单元格 + rows := xlsx.GetRows("Sheet1") + for _, row := range rows { + for _, colCell := range row { + fmt.Print(colCell, "\t") + } + fmt.Println() + } +} +``` + +### 在 Excel 文档中创建图表 + +使用 Excelize 生成图表十分简单,仅需几行代码。您可以根据工作表中的已有数据构建图表,或向工作表中添加数据并创建图表。 + +

Excelize

+ +```go +package main + +import ( + "fmt" + + "github.com/360EntSecGroup-Skylar/excelize" +) + +func main() { + categories := map[string]string{"A2": "Small", "A3": "Normal", "A4": "Large", "B1": "Apple", "C1": "Orange", "D1": "Pear"} + values := map[string]int{"B2": 2, "C2": 3, "D2": 3, "B3": 5, "C3": 2, "D3": 4, "B4": 6, "C4": 7, "D4": 8} + xlsx := excelize.NewFile() + for k, v := range categories { + xlsx.SetCellValue("Sheet1", k, v) + } + for k, v := range values { + xlsx.SetCellValue("Sheet1", k, v) + } + xlsx.AddChart("Sheet1", "E1", `{"type":"col3DClustered","series":[{"name":"Sheet1!$A$2","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$2:$D$2"},{"name":"Sheet1!$A$3","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$3:$D$3"},{"name":"Sheet1!$A$4","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"}],"title":{"name":"Fruit 3D Clustered Column Chart"}}`) + // 根据指定路径保存文件 + err := xlsx.SaveAs("./Book1.xlsx") + if err != nil { + fmt.Println(err) + } +} + +``` + +### 向 Excel 文档中插入图片 + +```go +package main + +import ( + "fmt" + _ "image/gif" + _ "image/jpeg" + _ "image/png" + + "github.com/360EntSecGroup-Skylar/excelize" +) + +func main() { + xlsx, err := excelize.OpenFile("./Book1.xlsx") + if err != nil { + fmt.Println(err) + return + } + // 插入图片 + err = xlsx.AddPicture("Sheet1", "A2", "./image1.png", "") + if err != nil { + fmt.Println(err) + } + // 在工作表中插入图片,并设置图片的缩放比例 + err = xlsx.AddPicture("Sheet1", "D2", "./image2.jpg", `{"x_scale": 0.5, "y_scale": 0.5}`) + if err != nil { + fmt.Println(err) + } + // 在工作表中插入图片,并设置图片的打印属性 + err = xlsx.AddPicture("Sheet1", "H2", "./image3.gif", `{"x_offset": 15, "y_offset": 10, "print_obj": true, "lock_aspect_ratio": false, "locked": false}`) + if err != nil { + fmt.Println(err) + } + // 保存文件 + err = xlsx.Save() + if err != nil { + fmt.Println(err) + } +} +``` + +## 社区合作 + +欢迎您为此项目贡献代码,提出建议或问题、修复 Bug 以及参与讨论对新功能的想法。 XML 符合标准: [part 1 of the 5th edition of the ECMA-376 Standard for Office Open XML](http://www.ecma-international.org/publications/standards/Ecma-376.htm)。 + +## 致谢 + +本类库中部分 XML 结构体的定义参考了开源项目:[tealeg/xlsx](https://github.com/tealeg/xlsx). + +## 开源许可 + +本项目遵循 BSD 3-Clause 开源许可协议,访问 [https://opensource.org/licenses/BSD-3-Clause](https://opensource.org/licenses/BSD-3-Clause) 查看许可协议文件。 + +[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2F360EntSecGroup-Skylar%2Fexcelize.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2F360EntSecGroup-Skylar%2Fexcelize?ref=badge_large) diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/cell.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/cell.go new file mode 100644 index 0000000000..afe8635f8c --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/cell.go @@ -0,0 +1,599 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. + +package excelize + +import ( + "encoding/xml" + "fmt" + "reflect" + "strconv" + "strings" + "time" +) + +const ( + // STCellFormulaTypeArray defined the formula is an array formula. + STCellFormulaTypeArray = "array" + // STCellFormulaTypeDataTable defined the formula is a data table formula. + STCellFormulaTypeDataTable = "dataTable" + // STCellFormulaTypeNormal defined the formula is a regular cell formula. + STCellFormulaTypeNormal = "normal" + // STCellFormulaTypeShared defined the formula is part of a shared formula. + STCellFormulaTypeShared = "shared" +) + +// mergeCellsParser provides a function to check merged cells in worksheet by +// given axis. +func (f *File) mergeCellsParser(xlsx *xlsxWorksheet, axis string) string { + axis = strings.ToUpper(axis) + if xlsx.MergeCells != nil { + for i := 0; i < len(xlsx.MergeCells.Cells); i++ { + if checkCellInArea(axis, xlsx.MergeCells.Cells[i].Ref) { + axis = strings.Split(xlsx.MergeCells.Cells[i].Ref, ":")[0] + } + } + } + return axis +} + +// SetCellValue provides a function to set value of a cell. The following +// shows the supported data types: +// +// int +// int8 +// int16 +// int32 +// int64 +// uint +// uint8 +// uint16 +// uint32 +// uint64 +// float32 +// float64 +// string +// []byte +// time.Duration +// time.Time +// bool +// nil +// +// Note that default date format is m/d/yy h:mm of time.Time type value. You can +// set numbers format by SetCellStyle() method. +func (f *File) SetCellValue(sheet, axis string, value interface{}) { + switch t := value.(type) { + case float32: + f.SetCellDefault(sheet, axis, strconv.FormatFloat(float64(value.(float32)), 'f', -1, 32)) + case float64: + f.SetCellDefault(sheet, axis, strconv.FormatFloat(float64(value.(float64)), 'f', -1, 64)) + case string: + f.SetCellStr(sheet, axis, t) + case []byte: + f.SetCellStr(sheet, axis, string(t)) + case time.Duration: + f.SetCellDefault(sheet, axis, strconv.FormatFloat(float64(value.(time.Duration).Seconds()/86400), 'f', -1, 32)) + f.setDefaultTimeStyle(sheet, axis, 21) + case time.Time: + f.SetCellDefault(sheet, axis, strconv.FormatFloat(float64(timeToExcelTime(timeToUTCTime(value.(time.Time)))), 'f', -1, 64)) + f.setDefaultTimeStyle(sheet, axis, 22) + case nil: + f.SetCellStr(sheet, axis, "") + case bool: + f.SetCellBool(sheet, axis, bool(value.(bool))) + default: + f.setCellIntValue(sheet, axis, value) + } +} + +// setCellIntValue provides a function to set int value of a cell. +func (f *File) setCellIntValue(sheet, axis string, value interface{}) { + switch value.(type) { + case int: + f.SetCellInt(sheet, axis, value.(int)) + case int8: + f.SetCellInt(sheet, axis, int(value.(int8))) + case int16: + f.SetCellInt(sheet, axis, int(value.(int16))) + case int32: + f.SetCellInt(sheet, axis, int(value.(int32))) + case int64: + f.SetCellInt(sheet, axis, int(value.(int64))) + case uint: + f.SetCellInt(sheet, axis, int(value.(uint))) + case uint8: + f.SetCellInt(sheet, axis, int(value.(uint8))) + case uint16: + f.SetCellInt(sheet, axis, int(value.(uint16))) + case uint32: + f.SetCellInt(sheet, axis, int(value.(uint32))) + case uint64: + f.SetCellInt(sheet, axis, int(value.(uint64))) + default: + f.SetCellStr(sheet, axis, fmt.Sprintf("%v", value)) + } +} + +// SetCellBool provides a function to set bool type value of a cell by given +// worksheet name, cell coordinates and cell value. +func (f *File) SetCellBool(sheet, axis string, value bool) { + xlsx := f.workSheetReader(sheet) + axis = f.mergeCellsParser(xlsx, axis) + col := string(strings.Map(letterOnlyMapF, axis)) + row, err := strconv.Atoi(strings.Map(intOnlyMapF, axis)) + if err != nil { + return + } + xAxis := row - 1 + yAxis := TitleToNumber(col) + + rows := xAxis + 1 + cell := yAxis + 1 + + completeRow(xlsx, rows, cell) + completeCol(xlsx, rows, cell) + + xlsx.SheetData.Row[xAxis].C[yAxis].S = f.prepareCellStyle(xlsx, cell, xlsx.SheetData.Row[xAxis].C[yAxis].S) + xlsx.SheetData.Row[xAxis].C[yAxis].T = "b" + if value { + xlsx.SheetData.Row[xAxis].C[yAxis].V = "1" + } else { + xlsx.SheetData.Row[xAxis].C[yAxis].V = "0" + } +} + +// GetCellValue provides a function to get formatted value from cell by given +// worksheet name and axis in XLSX file. If it is possible to apply a format +// to the cell value, it will do so, if not then an error will be returned, +// along with the raw value of the cell. +func (f *File) GetCellValue(sheet, axis string) string { + xlsx := f.workSheetReader(sheet) + axis = f.mergeCellsParser(xlsx, axis) + row, err := strconv.Atoi(strings.Map(intOnlyMapF, axis)) + if err != nil { + return "" + } + xAxis := row - 1 + rows := len(xlsx.SheetData.Row) + if rows > 1 { + lastRow := xlsx.SheetData.Row[rows-1].R + if lastRow >= rows { + rows = lastRow + } + } + if rows < xAxis { + return "" + } + for k := range xlsx.SheetData.Row { + if xlsx.SheetData.Row[k].R == row { + for i := range xlsx.SheetData.Row[k].C { + if axis == xlsx.SheetData.Row[k].C[i].R { + val, _ := xlsx.SheetData.Row[k].C[i].getValueFrom(f, f.sharedStringsReader()) + return val + } + } + } + } + return "" +} + +// formattedValue provides a function to returns a value after formatted. If +// it is possible to apply a format to the cell value, it will do so, if not +// then an error will be returned, along with the raw value of the cell. +func (f *File) formattedValue(s int, v string) string { + if s == 0 { + return v + } + styleSheet := f.stylesReader() + ok := builtInNumFmtFunc[styleSheet.CellXfs.Xf[s].NumFmtID] + if ok != nil { + return ok(styleSheet.CellXfs.Xf[s].NumFmtID, v) + } + return v +} + +// GetCellStyle provides a function to get cell style index by given worksheet +// name and cell coordinates. +func (f *File) GetCellStyle(sheet, axis string) int { + xlsx := f.workSheetReader(sheet) + axis = f.mergeCellsParser(xlsx, axis) + col := string(strings.Map(letterOnlyMapF, axis)) + row, err := strconv.Atoi(strings.Map(intOnlyMapF, axis)) + if err != nil { + return 0 + } + xAxis := row - 1 + yAxis := TitleToNumber(col) + + rows := xAxis + 1 + cell := yAxis + 1 + + completeRow(xlsx, rows, cell) + completeCol(xlsx, rows, cell) + + return f.prepareCellStyle(xlsx, cell, xlsx.SheetData.Row[xAxis].C[yAxis].S) +} + +// GetCellFormula provides a function to get formula from cell by given +// worksheet name and axis in XLSX file. +func (f *File) GetCellFormula(sheet, axis string) string { + xlsx := f.workSheetReader(sheet) + axis = f.mergeCellsParser(xlsx, axis) + row, err := strconv.Atoi(strings.Map(intOnlyMapF, axis)) + if err != nil { + return "" + } + xAxis := row - 1 + rows := len(xlsx.SheetData.Row) + if rows > 1 { + lastRow := xlsx.SheetData.Row[rows-1].R + if lastRow >= rows { + rows = lastRow + } + } + if rows < xAxis { + return "" + } + for k := range xlsx.SheetData.Row { + if xlsx.SheetData.Row[k].R == row { + for i := range xlsx.SheetData.Row[k].C { + if axis == xlsx.SheetData.Row[k].C[i].R { + if xlsx.SheetData.Row[k].C[i].F == nil { + continue + } + if xlsx.SheetData.Row[k].C[i].F.T == STCellFormulaTypeShared { + return getSharedForumula(xlsx, xlsx.SheetData.Row[k].C[i].F.Si) + } + return xlsx.SheetData.Row[k].C[i].F.Content + } + } + } + } + return "" +} + +// getSharedForumula find a cell contains the same formula as another cell, +// the "shared" value can be used for the t attribute and the si attribute can +// be used to refer to the cell containing the formula. Two formulas are +// considered to be the same when their respective representations in +// R1C1-reference notation, are the same. +// +// Note that this function not validate ref tag to check the cell if or not in +// allow area, and always return origin shared formula. +func getSharedForumula(xlsx *xlsxWorksheet, si string) string { + for k := range xlsx.SheetData.Row { + for i := range xlsx.SheetData.Row[k].C { + if xlsx.SheetData.Row[k].C[i].F == nil { + continue + } + if xlsx.SheetData.Row[k].C[i].F.T != STCellFormulaTypeShared { + continue + } + if xlsx.SheetData.Row[k].C[i].F.Si != si { + continue + } + if xlsx.SheetData.Row[k].C[i].F.Ref != "" { + return xlsx.SheetData.Row[k].C[i].F.Content + } + } + } + return "" +} + +// SetCellFormula provides a function to set cell formula by given string and +// worksheet name. +func (f *File) SetCellFormula(sheet, axis, formula string) { + xlsx := f.workSheetReader(sheet) + axis = f.mergeCellsParser(xlsx, axis) + col := string(strings.Map(letterOnlyMapF, axis)) + row, err := strconv.Atoi(strings.Map(intOnlyMapF, axis)) + if err != nil { + return + } + xAxis := row - 1 + yAxis := TitleToNumber(col) + + rows := xAxis + 1 + cell := yAxis + 1 + + completeRow(xlsx, rows, cell) + completeCol(xlsx, rows, cell) + + if xlsx.SheetData.Row[xAxis].C[yAxis].F != nil { + xlsx.SheetData.Row[xAxis].C[yAxis].F.Content = formula + } else { + f := xlsxF{ + Content: formula, + } + xlsx.SheetData.Row[xAxis].C[yAxis].F = &f + } +} + +// SetCellHyperLink provides a function to set cell hyperlink by given +// worksheet name and link URL address. LinkType defines two types of +// hyperlink "External" for web site or "Location" for moving to one of cell +// in this workbook. The below is example for external link. +// +// xlsx.SetCellHyperLink("Sheet1", "A3", "https://github.com/360EntSecGroup-Skylar/excelize", "External") +// // Set underline and font color style for the cell. +// style, _ := xlsx.NewStyle(`{"font":{"color":"#1265BE","underline":"single"}}`) +// xlsx.SetCellStyle("Sheet1", "A3", "A3", style) +// +// A this is another example for "Location": +// +// xlsx.SetCellHyperLink("Sheet1", "A3", "Sheet1!A40", "Location") +// +func (f *File) SetCellHyperLink(sheet, axis, link, linkType string) { + xlsx := f.workSheetReader(sheet) + axis = f.mergeCellsParser(xlsx, axis) + linkTypes := map[string]xlsxHyperlink{ + "External": {}, + "Location": {Location: link}, + } + hyperlink, ok := linkTypes[linkType] + if !ok || axis == "" { + return + } + hyperlink.Ref = axis + if linkType == "External" { + rID := f.addSheetRelationships(sheet, SourceRelationshipHyperLink, link, linkType) + hyperlink.RID = "rId" + strconv.Itoa(rID) + } + if xlsx.Hyperlinks == nil { + xlsx.Hyperlinks = &xlsxHyperlinks{} + } + xlsx.Hyperlinks.Hyperlink = append(xlsx.Hyperlinks.Hyperlink, hyperlink) +} + +// GetCellHyperLink provides a function to get cell hyperlink by given +// worksheet name and axis. Boolean type value link will be ture if the cell +// has a hyperlink and the target is the address of the hyperlink. Otherwise, +// the value of link will be false and the value of the target will be a blank +// string. For example get hyperlink of Sheet1!H6: +// +// link, target := xlsx.GetCellHyperLink("Sheet1", "H6") +// +func (f *File) GetCellHyperLink(sheet, axis string) (bool, string) { + var link bool + var target string + xlsx := f.workSheetReader(sheet) + axis = f.mergeCellsParser(xlsx, axis) + if xlsx.Hyperlinks == nil || axis == "" { + return link, target + } + for h := range xlsx.Hyperlinks.Hyperlink { + if xlsx.Hyperlinks.Hyperlink[h].Ref == axis { + link = true + target = xlsx.Hyperlinks.Hyperlink[h].Location + if xlsx.Hyperlinks.Hyperlink[h].RID != "" { + target = f.getSheetRelationshipsTargetByID(sheet, xlsx.Hyperlinks.Hyperlink[h].RID) + } + } + } + return link, target +} + +// MergeCell provides a function to merge cells by given coordinate area and +// sheet name. For example create a merged cell of D3:E9 on Sheet1: +// +// xlsx.MergeCell("Sheet1", "D3", "E9") +// +// If you create a merged cell that overlaps with another existing merged cell, +// those merged cells that already exist will be removed. +func (f *File) MergeCell(sheet, hcell, vcell string) { + if hcell == vcell { + return + } + + hcell = strings.ToUpper(hcell) + vcell = strings.ToUpper(vcell) + + // Coordinate conversion, convert C1:B3 to 2,0,1,2. + hcol := string(strings.Map(letterOnlyMapF, hcell)) + hrow, _ := strconv.Atoi(strings.Map(intOnlyMapF, hcell)) + hyAxis := hrow - 1 + hxAxis := TitleToNumber(hcol) + + vcol := string(strings.Map(letterOnlyMapF, vcell)) + vrow, _ := strconv.Atoi(strings.Map(intOnlyMapF, vcell)) + vyAxis := vrow - 1 + vxAxis := TitleToNumber(vcol) + + if vxAxis < hxAxis { + hcell, vcell = vcell, hcell + vxAxis, hxAxis = hxAxis, vxAxis + } + + if vyAxis < hyAxis { + hcell, vcell = vcell, hcell + vyAxis, hyAxis = hyAxis, vyAxis + } + + xlsx := f.workSheetReader(sheet) + if xlsx.MergeCells != nil { + mergeCell := xlsxMergeCell{} + // Correct the coordinate area, such correct C1:B3 to B1:C3. + mergeCell.Ref = ToAlphaString(hxAxis) + strconv.Itoa(hyAxis+1) + ":" + ToAlphaString(vxAxis) + strconv.Itoa(vyAxis+1) + // Delete the merged cells of the overlapping area. + for i := 0; i < len(xlsx.MergeCells.Cells); i++ { + if checkCellInArea(hcell, xlsx.MergeCells.Cells[i].Ref) || checkCellInArea(strings.Split(xlsx.MergeCells.Cells[i].Ref, ":")[0], mergeCell.Ref) { + xlsx.MergeCells.Cells = append(xlsx.MergeCells.Cells[:i], xlsx.MergeCells.Cells[i+1:]...) + } else if checkCellInArea(vcell, xlsx.MergeCells.Cells[i].Ref) || checkCellInArea(strings.Split(xlsx.MergeCells.Cells[i].Ref, ":")[1], mergeCell.Ref) { + xlsx.MergeCells.Cells = append(xlsx.MergeCells.Cells[:i], xlsx.MergeCells.Cells[i+1:]...) + } + } + xlsx.MergeCells.Cells = append(xlsx.MergeCells.Cells, &mergeCell) + } else { + mergeCell := xlsxMergeCell{} + // Correct the coordinate area, such correct C1:B3 to B1:C3. + mergeCell.Ref = ToAlphaString(hxAxis) + strconv.Itoa(hyAxis+1) + ":" + ToAlphaString(vxAxis) + strconv.Itoa(vyAxis+1) + mergeCells := xlsxMergeCells{} + mergeCells.Cells = append(mergeCells.Cells, &mergeCell) + xlsx.MergeCells = &mergeCells + } +} + +// SetCellInt provides a function to set int type value of a cell by given +// worksheet name, cell coordinates and cell value. +func (f *File) SetCellInt(sheet, axis string, value int) { + xlsx := f.workSheetReader(sheet) + axis = f.mergeCellsParser(xlsx, axis) + col := string(strings.Map(letterOnlyMapF, axis)) + row, err := strconv.Atoi(strings.Map(intOnlyMapF, axis)) + if err != nil { + return + } + xAxis := row - 1 + yAxis := TitleToNumber(col) + + rows := xAxis + 1 + cell := yAxis + 1 + + completeRow(xlsx, rows, cell) + completeCol(xlsx, rows, cell) + + xlsx.SheetData.Row[xAxis].C[yAxis].S = f.prepareCellStyle(xlsx, cell, xlsx.SheetData.Row[xAxis].C[yAxis].S) + xlsx.SheetData.Row[xAxis].C[yAxis].T = "" + xlsx.SheetData.Row[xAxis].C[yAxis].V = strconv.Itoa(value) +} + +// prepareCellStyle provides a function to prepare style index of cell in +// worksheet by given column index and style index. +func (f *File) prepareCellStyle(xlsx *xlsxWorksheet, col, style int) int { + if xlsx.Cols != nil && style == 0 { + for _, v := range xlsx.Cols.Col { + if v.Min <= col && col <= v.Max { + style = v.Style + } + } + } + return style +} + +// SetCellStr provides a function to set string type value of a cell. Total +// number of characters that a cell can contain 32767 characters. +func (f *File) SetCellStr(sheet, axis, value string) { + xlsx := f.workSheetReader(sheet) + axis = f.mergeCellsParser(xlsx, axis) + if len(value) > 32767 { + value = value[0:32767] + } + col := string(strings.Map(letterOnlyMapF, axis)) + row, err := strconv.Atoi(strings.Map(intOnlyMapF, axis)) + if err != nil { + return + } + xAxis := row - 1 + yAxis := TitleToNumber(col) + + rows := xAxis + 1 + cell := yAxis + 1 + + completeRow(xlsx, rows, cell) + completeCol(xlsx, rows, cell) + + // Leading space(s) character detection. + if len(value) > 0 { + if value[0] == 32 { + xlsx.SheetData.Row[xAxis].C[yAxis].XMLSpace = xml.Attr{ + Name: xml.Name{Space: NameSpaceXML, Local: "space"}, + Value: "preserve", + } + } + } + xlsx.SheetData.Row[xAxis].C[yAxis].S = f.prepareCellStyle(xlsx, cell, xlsx.SheetData.Row[xAxis].C[yAxis].S) + xlsx.SheetData.Row[xAxis].C[yAxis].T = "str" + xlsx.SheetData.Row[xAxis].C[yAxis].V = value +} + +// SetCellDefault provides a function to set string type value of a cell as +// default format without escaping the cell. +func (f *File) SetCellDefault(sheet, axis, value string) { + xlsx := f.workSheetReader(sheet) + axis = f.mergeCellsParser(xlsx, axis) + col := string(strings.Map(letterOnlyMapF, axis)) + row, err := strconv.Atoi(strings.Map(intOnlyMapF, axis)) + if err != nil { + return + } + xAxis := row - 1 + yAxis := TitleToNumber(col) + + rows := xAxis + 1 + cell := yAxis + 1 + + completeRow(xlsx, rows, cell) + completeCol(xlsx, rows, cell) + + xlsx.SheetData.Row[xAxis].C[yAxis].S = f.prepareCellStyle(xlsx, cell, xlsx.SheetData.Row[xAxis].C[yAxis].S) + xlsx.SheetData.Row[xAxis].C[yAxis].T = "" + xlsx.SheetData.Row[xAxis].C[yAxis].V = value +} + +// SetSheetRow writes an array to row by given worksheet name, starting +// coordinate and a pointer to array type 'slice'. For example, writes an +// array to row 6 start with the cell B6 on Sheet1: +// +// xlsx.SetSheetRow("Sheet1", "B6", &[]interface{}{"1", nil, 2}) +// +func (f *File) SetSheetRow(sheet, axis string, slice interface{}) { + xlsx := f.workSheetReader(sheet) + axis = f.mergeCellsParser(xlsx, axis) + col := string(strings.Map(letterOnlyMapF, axis)) + row, err := strconv.Atoi(strings.Map(intOnlyMapF, axis)) + if err != nil { + return + } + // Make sure 'slice' is a Ptr to Slice + v := reflect.ValueOf(slice) + if v.Kind() != reflect.Ptr { + return + } + v = v.Elem() + if v.Kind() != reflect.Slice { + return + } + + xAxis := row - 1 + yAxis := TitleToNumber(col) + + rows := xAxis + 1 + cell := yAxis + 1 + + completeRow(xlsx, rows, cell) + completeCol(xlsx, rows, cell) + + idx := 0 + for i := cell - 1; i < v.Len()+cell-1; i++ { + c := ToAlphaString(i) + strconv.Itoa(row) + f.SetCellValue(sheet, c, v.Index(idx).Interface()) + idx++ + } +} + +// checkCellInArea provides a function to determine if a given coordinate is +// within an area. +func checkCellInArea(cell, area string) bool { + cell = strings.ToUpper(cell) + area = strings.ToUpper(area) + + ref := strings.Split(area, ":") + if len(ref) < 2 { + return false + } + + from := ref[0] + to := ref[1] + + col, row := getCellColRow(cell) + fromCol, fromRow := getCellColRow(from) + toCol, toRow := getCellColRow(to) + + return axisLowerOrEqualThan(fromCol, col) && axisLowerOrEqualThan(col, toCol) && axisLowerOrEqualThan(fromRow, row) && axisLowerOrEqualThan(row, toRow) +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/chart.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/chart.go new file mode 100644 index 0000000000..77a012543e --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/chart.go @@ -0,0 +1,1291 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. + +package excelize + +import ( + "encoding/json" + "encoding/xml" + "strconv" + "strings" +) + +// This section defines the currently supported chart types. +const ( + Area = "area" + AreaStacked = "areaStacked" + AreaPercentStacked = "areaPercentStacked" + Area3D = "area3D" + Area3DStacked = "area3DStacked" + Area3DPercentStacked = "area3DPercentStacked" + Bar = "bar" + BarStacked = "barStacked" + BarPercentStacked = "barPercentStacked" + Bar3DClustered = "bar3DClustered" + Bar3DStacked = "bar3DStacked" + Bar3DPercentStacked = "bar3DPercentStacked" + Col = "col" + ColStacked = "colStacked" + ColPercentStacked = "colPercentStacked" + Col3DClustered = "col3DClustered" + Col3D = "col3D" + Col3DStacked = "col3DStacked" + Col3DPercentStacked = "col3DPercentStacked" + Doughnut = "doughnut" + Line = "line" + Pie = "pie" + Pie3D = "pie3D" + Radar = "radar" + Scatter = "scatter" +) + +// This section defines the default value of chart properties. +var ( + chartView3DRotX = map[string]int{ + Area: 0, + AreaStacked: 0, + AreaPercentStacked: 0, + Area3D: 15, + Area3DStacked: 15, + Area3DPercentStacked: 15, + Bar: 0, + BarStacked: 0, + BarPercentStacked: 0, + Bar3DClustered: 15, + Bar3DStacked: 15, + Bar3DPercentStacked: 15, + Col: 0, + ColStacked: 0, + ColPercentStacked: 0, + Col3DClustered: 15, + Col3D: 15, + Col3DStacked: 15, + Col3DPercentStacked: 15, + Doughnut: 0, + Line: 0, + Pie: 0, + Pie3D: 30, + Radar: 0, + Scatter: 0, + } + chartView3DRotY = map[string]int{ + Area: 0, + AreaStacked: 0, + AreaPercentStacked: 0, + Area3D: 20, + Area3DStacked: 20, + Area3DPercentStacked: 20, + Bar: 0, + BarStacked: 0, + BarPercentStacked: 0, + Bar3DClustered: 20, + Bar3DStacked: 20, + Bar3DPercentStacked: 20, + Col: 0, + ColStacked: 0, + ColPercentStacked: 0, + Col3DClustered: 20, + Col3D: 20, + Col3DStacked: 20, + Col3DPercentStacked: 20, + Doughnut: 0, + Line: 0, + Pie: 0, + Pie3D: 0, + Radar: 0, + Scatter: 0, + } + chartView3DDepthPercent = map[string]int{ + Area: 100, + AreaStacked: 100, + AreaPercentStacked: 100, + Area3D: 100, + Area3DStacked: 100, + Area3DPercentStacked: 100, + Bar: 100, + BarStacked: 100, + BarPercentStacked: 100, + Bar3DClustered: 100, + Bar3DStacked: 100, + Bar3DPercentStacked: 100, + Col: 100, + ColStacked: 100, + ColPercentStacked: 100, + Col3DClustered: 100, + Col3D: 100, + Col3DStacked: 100, + Col3DPercentStacked: 100, + Doughnut: 100, + Line: 100, + Pie: 100, + Pie3D: 100, + Radar: 100, + Scatter: 100, + } + chartView3DRAngAx = map[string]int{ + Area: 0, + AreaStacked: 0, + AreaPercentStacked: 0, + Area3D: 1, + Area3DStacked: 1, + Area3DPercentStacked: 1, + Bar: 0, + BarStacked: 0, + BarPercentStacked: 0, + Bar3DClustered: 1, + Bar3DStacked: 1, + Bar3DPercentStacked: 1, + Col: 0, + ColStacked: 0, + ColPercentStacked: 0, + Col3DClustered: 1, + Col3D: 1, + Col3DStacked: 1, + Col3DPercentStacked: 1, + Doughnut: 0, + Line: 0, + Pie: 0, + Pie3D: 0, + Radar: 0, + Scatter: 0, + } + chartLegendPosition = map[string]string{ + "bottom": "b", + "left": "l", + "right": "r", + "top": "t", + "top_right": "tr", + } + chartValAxNumFmtFormatCode = map[string]string{ + Area: "General", + AreaStacked: "General", + AreaPercentStacked: "0%", + Area3D: "General", + Area3DStacked: "General", + Area3DPercentStacked: "0%", + Bar: "General", + BarStacked: "General", + BarPercentStacked: "0%", + Bar3DClustered: "General", + Bar3DStacked: "General", + Bar3DPercentStacked: "0%", + Col: "General", + ColStacked: "General", + ColPercentStacked: "0%", + Col3DClustered: "General", + Col3D: "General", + Col3DStacked: "General", + Col3DPercentStacked: "0%", + Doughnut: "General", + Line: "General", + Pie: "General", + Pie3D: "General", + Radar: "General", + Scatter: "General", + } + chartValAxCrossBetween = map[string]string{ + Area: "midCat", + AreaStacked: "midCat", + AreaPercentStacked: "midCat", + Area3D: "midCat", + Area3DStacked: "midCat", + Area3DPercentStacked: "midCat", + Bar: "between", + BarStacked: "between", + BarPercentStacked: "between", + Bar3DClustered: "between", + Bar3DStacked: "between", + Bar3DPercentStacked: "between", + Col: "between", + ColStacked: "between", + ColPercentStacked: "between", + Col3DClustered: "between", + Col3D: "between", + Col3DStacked: "between", + Col3DPercentStacked: "between", + Doughnut: "between", + Line: "between", + Pie: "between", + Pie3D: "between", + Radar: "between", + Scatter: "between", + } + plotAreaChartGrouping = map[string]string{ + Area: "standard", + AreaStacked: "stacked", + AreaPercentStacked: "percentStacked", + Area3D: "standard", + Area3DStacked: "stacked", + Area3DPercentStacked: "percentStacked", + Bar: "clustered", + BarStacked: "stacked", + BarPercentStacked: "percentStacked", + Bar3DClustered: "clustered", + Bar3DStacked: "stacked", + Bar3DPercentStacked: "percentStacked", + Col: "clustered", + ColStacked: "stacked", + ColPercentStacked: "percentStacked", + Col3DClustered: "clustered", + Col3D: "standard", + Col3DStacked: "stacked", + Col3DPercentStacked: "percentStacked", + Line: "standard", + } + plotAreaChartBarDir = map[string]string{ + Bar: "bar", + BarStacked: "bar", + BarPercentStacked: "bar", + Bar3DClustered: "bar", + Bar3DStacked: "bar", + Bar3DPercentStacked: "bar", + Col: "col", + ColStacked: "col", + ColPercentStacked: "col", + Col3DClustered: "col", + Col3D: "col", + Col3DStacked: "col", + Col3DPercentStacked: "col", + Line: "standard", + } + orientation = map[bool]string{ + true: "maxMin", + false: "minMax", + } + catAxPos = map[bool]string{ + true: "t", + false: "b", + } + valAxPos = map[bool]string{ + true: "r", + false: "l", + } +) + +// parseFormatChartSet provides a function to parse the format settings of the +// chart with default value. +func parseFormatChartSet(formatSet string) (*formatChart, error) { + format := formatChart{ + Dimension: formatChartDimension{ + Width: 480, + Height: 290, + }, + Format: formatPicture{ + FPrintsWithSheet: true, + FLocksWithSheet: false, + NoChangeAspect: false, + OffsetX: 0, + OffsetY: 0, + XScale: 1.0, + YScale: 1.0, + }, + Legend: formatChartLegend{ + Position: "bottom", + ShowLegendKey: false, + }, + Title: formatChartTitle{ + Name: " ", + }, + ShowBlanksAs: "gap", + } + err := json.Unmarshal([]byte(formatSet), &format) + return &format, err +} + +// AddChart provides the method to add chart in a sheet by given chart format +// set (such as offset, scale, aspect ratio setting and print settings) and +// properties set. For example, create 3D clustered column chart with data +// Sheet1!$A$29:$D$32: +// +// package main +// +// import ( +// "fmt" +// +// "github.com/360EntSecGroup-Skylar/excelize" +// ) +// +// func main() { +// categories := map[string]string{"A2": "Small", "A3": "Normal", "A4": "Large", "B1": "Apple", "C1": "Orange", "D1": "Pear"} +// values := map[string]int{"B2": 2, "C2": 3, "D2": 3, "B3": 5, "C3": 2, "D3": 4, "B4": 6, "C4": 7, "D4": 8} +// xlsx := excelize.NewFile() +// for k, v := range categories { +// xlsx.SetCellValue("Sheet1", k, v) +// } +// for k, v := range values { +// xlsx.SetCellValue("Sheet1", k, v) +// } +// xlsx.AddChart("Sheet1", "E1", `{"type":"col3DClustered","dimension":{"width":640,"height":480},"series":[{"name":"Sheet1!$A$2","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$2:$D$2"},{"name":"Sheet1!$A$3","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$3:$D$3"},{"name":"Sheet1!$A$4","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"}],"format":{"x_scale":1.0,"y_scale":1.0,"x_offset":15,"y_offset":10,"print_obj":true,"lock_aspect_ratio":false,"locked":false},"legend":{"position":"bottom","show_legend_key":false},"title":{"name":"Fruit 3D Clustered Column Chart"},"plotarea":{"show_bubble_size":true,"show_cat_name":false,"show_leader_lines":false,"show_percent":true,"show_series_name":true,"show_val":true},"show_blanks_as":"zero","x_axis":{"reverse_order":true},"y_axis":{"maximum":7.5,"minimum":0.5}}`) +// // Save xlsx file by the given path. +// err := xlsx.SaveAs("./Book1.xlsx") +// if err != nil { +// fmt.Println(err) +// } +// } +// +// The following shows the type of chart supported by excelize: +// +// Type | Chart +// ----------------------+------------------------------ +// area | 2D area chart +// areaStacked | 2D stacked area chart +// areaPercentStacked | 2D 100% stacked area chart +// area3D | 3D area chart +// area3DStacked | 3D stacked area chart +// area3DPercentStacked | 3D 100% stacked area chart +// bar | 2D clustered bar chart +// barStacked | 2D stacked bar chart +// barPercentStacked | 2D 100% stacked bar chart +// bar3DClustered | 3D clustered bar chart +// bar3DStacked | 3D stacked bar chart +// bar3DPercentStacked | 3D 100% stacked bar chart +// col | 2D clustered column chart +// colStacked | 2D stacked column chart +// colPercentStacked | 2D 100% stacked column chart +// col3DClustered | 3D clustered column chart +// col3D | 3D column chart +// col3DStacked | 3D stacked column chart +// col3DPercentStacked | 3D 100% stacked column chart +// doughnut | doughnut chart +// line | line chart +// pie | pie chart +// pie3D | 3D pie chart +// radar | radar chart +// scatter | scatter chart +// +// In Excel a chart series is a collection of information that defines which data is plotted such as values, axis labels and formatting. +// +// The series options that can be set are: +// +// name +// categories +// values +// +// name: Set the name for the series. The name is displayed in the chart legend and in the formula bar. The name property is optional and if it isn't supplied it will default to Series 1..n. The name can also be a formula such as Sheet1!$A$1 +// +// categories: This sets the chart category labels. The category is more or less the same as the X axis. In most chart types the categories property is optional and the chart will just assume a sequential series from 1..n. +// +// values: This is the most important property of a series and is the only mandatory option for every chart object. This option links the chart with the worksheet data that it displays. +// +// Set properties of the chart legend. The options that can be set are: +// +// position +// show_legend_key +// +// position: Set the position of the chart legend. The default legend position is right. The available positions are: +// +// top +// bottom +// left +// right +// top_right +// +// show_legend_key: Set the legend keys shall be shown in data labels. The default value is false. +// +// Set properties of the chart title. The properties that can be set are: +// +// title +// +// name: Set the name (title) for the chart. The name is displayed above the chart. The name can also be a formula such as Sheet1!$A$1 or a list with a sheetname. The name property is optional. The default is to have no chart title. +// +// Specifies how blank cells are plotted on the chart by show_blanks_as. The default value is gap. The options that can be set are: +// +// gap +// span +// zero +// +// gap: Specifies that blank values shall be left as a gap. +// +// sapn: Specifies that blank values shall be spanned with a line. +// +// zero: Specifies that blank values shall be treated as zero. +// +// Set chart offset, scale, aspect ratio setting and print settings by format, same as function AddPicture. +// +// Set the position of the chart plot area by plotarea. The properties that can be set are: +// +// show_bubble_size +// show_cat_name +// show_leader_lines +// show_percent +// show_series_name +// show_val +// +// show_bubble_size: Specifies the bubble size shall be shown in a data label. The show_bubble_size property is optional. The default value is false. +// +// show_cat_name: Specifies that the category name shall be shown in the data label. The show_cat_name property is optional. The default value is true. +// +// show_leader_lines: Specifies leader lines shall be shown for data labels. The show_leader_lines property is optional. The default value is false. +// +// show_percent: Specifies that the percentage shall be shown in a data label. The show_percent property is optional. The default value is false. +// +// show_series_name: Specifies that the series name shall be shown in a data label. The show_series_name property is optional. The default value is false. +// +// show_val: Specifies that the value shall be shown in a data label. The show_val property is optional. The default value is false. +// +// Set the primary horizontal and vertical axis options by x_axis and y_axis. The properties that can be set are: +// +// reverse_order +// maximum +// minimum +// +// reverse_order: Specifies that the categories or values on reverse order (orientation of the chart). The reverse_order property is optional. The default value is false. +// +// maximum: Specifies that the fixed maximum, 0 is auto. The maximum property is optional. The default value is auto. +// +// minimum: Specifies that the fixed minimum, 0 is auto. The minimum property is optional. The default value is auto. +// +// Set chart size by dimension property. The dimension property is optional. The default width is 480, and height is 290. +// +func (f *File) AddChart(sheet, cell, format string) error { + formatSet, err := parseFormatChartSet(format) + if err != nil { + return err + } + // Read sheet data. + xlsx := f.workSheetReader(sheet) + // Add first picture for given sheet, create xl/drawings/ and xl/drawings/_rels/ folder. + drawingID := f.countDrawings() + 1 + chartID := f.countCharts() + 1 + drawingXML := "xl/drawings/drawing" + strconv.Itoa(drawingID) + ".xml" + drawingID, drawingXML = f.prepareDrawing(xlsx, drawingID, sheet, drawingXML) + drawingRID := f.addDrawingRelationships(drawingID, SourceRelationshipChart, "../charts/chart"+strconv.Itoa(chartID)+".xml", "") + f.addDrawingChart(sheet, drawingXML, cell, formatSet.Dimension.Width, formatSet.Dimension.Height, drawingRID, &formatSet.Format) + f.addChart(formatSet) + f.addContentTypePart(chartID, "chart") + f.addContentTypePart(drawingID, "drawings") + return err +} + +// countCharts provides a function to get chart files count storage in the +// folder xl/charts. +func (f *File) countCharts() int { + count := 0 + for k := range f.XLSX { + if strings.Contains(k, "xl/charts/chart") { + count++ + } + } + return count +} + +// prepareDrawing provides a function to prepare drawing ID and XML by given +// drawingID, worksheet name and default drawingXML. +func (f *File) prepareDrawing(xlsx *xlsxWorksheet, drawingID int, sheet, drawingXML string) (int, string) { + sheetRelationshipsDrawingXML := "../drawings/drawing" + strconv.Itoa(drawingID) + ".xml" + if xlsx.Drawing != nil { + // The worksheet already has a picture or chart relationships, use the relationships drawing ../drawings/drawing%d.xml. + sheetRelationshipsDrawingXML = f.getSheetRelationshipsTargetByID(sheet, xlsx.Drawing.RID) + drawingID, _ = strconv.Atoi(strings.TrimSuffix(strings.TrimPrefix(sheetRelationshipsDrawingXML, "../drawings/drawing"), ".xml")) + drawingXML = strings.Replace(sheetRelationshipsDrawingXML, "..", "xl", -1) + } else { + // Add first picture for given sheet. + rID := f.addSheetRelationships(sheet, SourceRelationshipDrawingML, sheetRelationshipsDrawingXML, "") + f.addSheetDrawing(sheet, rID) + } + return drawingID, drawingXML +} + +// addChart provides a function to create chart as xl/charts/chart%d.xml by +// given format sets. +func (f *File) addChart(formatSet *formatChart) { + count := f.countCharts() + xlsxChartSpace := xlsxChartSpace{ + XMLNSc: NameSpaceDrawingMLChart, + XMLNSa: NameSpaceDrawingML, + XMLNSr: SourceRelationship, + XMLNSc16r2: SourceRelationshipChart201506, + Date1904: &attrValBool{Val: false}, + Lang: &attrValString{Val: "en-US"}, + RoundedCorners: &attrValBool{Val: false}, + Chart: cChart{ + Title: &cTitle{ + Tx: cTx{ + Rich: &cRich{ + P: aP{ + PPr: &aPPr{ + DefRPr: aRPr{ + Kern: 1200, + Strike: "noStrike", + U: "none", + Sz: 1400, + SolidFill: &aSolidFill{ + SchemeClr: &aSchemeClr{ + Val: "tx1", + LumMod: &attrValInt{ + Val: 65000, + }, + LumOff: &attrValInt{ + Val: 35000, + }, + }, + }, + Ea: &aEa{ + Typeface: "+mn-ea", + }, + Cs: &aCs{ + Typeface: "+mn-cs", + }, + Latin: &aLatin{ + Typeface: "+mn-lt", + }, + }, + }, + R: &aR{ + RPr: aRPr{ + Lang: "en-US", + AltLang: "en-US", + }, + T: formatSet.Title.Name, + }, + }, + }, + }, + TxPr: cTxPr{ + P: aP{ + PPr: &aPPr{ + DefRPr: aRPr{ + Kern: 1200, + U: "none", + Sz: 14000, + Strike: "noStrike", + }, + }, + EndParaRPr: &aEndParaRPr{ + Lang: "en-US", + }, + }, + }, + }, + View3D: &cView3D{ + RotX: &attrValInt{Val: chartView3DRotX[formatSet.Type]}, + RotY: &attrValInt{Val: chartView3DRotY[formatSet.Type]}, + DepthPercent: &attrValInt{Val: chartView3DDepthPercent[formatSet.Type]}, + RAngAx: &attrValInt{Val: chartView3DRAngAx[formatSet.Type]}, + }, + Floor: &cThicknessSpPr{ + Thickness: &attrValInt{Val: 0}, + }, + SideWall: &cThicknessSpPr{ + Thickness: &attrValInt{Val: 0}, + }, + BackWall: &cThicknessSpPr{ + Thickness: &attrValInt{Val: 0}, + }, + PlotArea: &cPlotArea{}, + Legend: &cLegend{ + LegendPos: &attrValString{Val: chartLegendPosition[formatSet.Legend.Position]}, + Overlay: &attrValBool{Val: false}, + }, + + PlotVisOnly: &attrValBool{Val: false}, + DispBlanksAs: &attrValString{Val: formatSet.ShowBlanksAs}, + ShowDLblsOverMax: &attrValBool{Val: false}, + }, + SpPr: &cSpPr{ + SolidFill: &aSolidFill{ + SchemeClr: &aSchemeClr{Val: "bg1"}, + }, + Ln: &aLn{ + W: 9525, + Cap: "flat", + Cmpd: "sng", + Algn: "ctr", + SolidFill: &aSolidFill{ + SchemeClr: &aSchemeClr{Val: "tx1", + LumMod: &attrValInt{ + Val: 15000, + }, + LumOff: &attrValInt{ + Val: 85000, + }, + }, + }, + }, + }, + PrintSettings: &cPrintSettings{ + PageMargins: &cPageMargins{ + B: 0.75, + L: 0.7, + R: 0.7, + T: 0.7, + Header: 0.3, + Footer: 0.3, + }, + }, + } + plotAreaFunc := map[string]func(*formatChart) *cPlotArea{ + Area: f.drawBaseChart, + AreaStacked: f.drawBaseChart, + AreaPercentStacked: f.drawBaseChart, + Area3D: f.drawBaseChart, + Area3DStacked: f.drawBaseChart, + Area3DPercentStacked: f.drawBaseChart, + Bar: f.drawBaseChart, + BarStacked: f.drawBaseChart, + BarPercentStacked: f.drawBaseChart, + Bar3DClustered: f.drawBaseChart, + Bar3DStacked: f.drawBaseChart, + Bar3DPercentStacked: f.drawBaseChart, + Col: f.drawBaseChart, + ColStacked: f.drawBaseChart, + ColPercentStacked: f.drawBaseChart, + Col3DClustered: f.drawBaseChart, + Col3D: f.drawBaseChart, + Col3DStacked: f.drawBaseChart, + Col3DPercentStacked: f.drawBaseChart, + Doughnut: f.drawDoughnutChart, + Line: f.drawLineChart, + Pie3D: f.drawPie3DChart, + Pie: f.drawPieChart, + Radar: f.drawRadarChart, + Scatter: f.drawScatterChart, + } + xlsxChartSpace.Chart.PlotArea = plotAreaFunc[formatSet.Type](formatSet) + + chart, _ := xml.Marshal(xlsxChartSpace) + media := "xl/charts/chart" + strconv.Itoa(count+1) + ".xml" + f.saveFileList(media, chart) +} + +// drawBaseChart provides a function to draw the c:plotArea element for bar, +// and column series charts by given format sets. +func (f *File) drawBaseChart(formatSet *formatChart) *cPlotArea { + c := cCharts{ + BarDir: &attrValString{ + Val: "col", + }, + Grouping: &attrValString{ + Val: "clustered", + }, + VaryColors: &attrValBool{ + Val: true, + }, + Ser: f.drawChartSeries(formatSet), + DLbls: f.drawChartDLbls(formatSet), + AxID: []*attrValInt{ + {Val: 754001152}, + {Val: 753999904}, + }, + } + var ok bool + c.BarDir.Val, ok = plotAreaChartBarDir[formatSet.Type] + if !ok { + c.BarDir = nil + } + c.Grouping.Val = plotAreaChartGrouping[formatSet.Type] + if formatSet.Type == "colStacked" || formatSet.Type == "barStacked" || formatSet.Type == "barPercentStacked" || formatSet.Type == "colPercentStacked" || formatSet.Type == "areaPercentStacked" { + c.Overlap = &attrValInt{Val: 100} + } + catAx := f.drawPlotAreaCatAx(formatSet) + valAx := f.drawPlotAreaValAx(formatSet) + charts := map[string]*cPlotArea{ + "area": { + AreaChart: &c, + CatAx: catAx, + ValAx: valAx, + }, + "areaStacked": { + AreaChart: &c, + CatAx: catAx, + ValAx: valAx, + }, + "areaPercentStacked": { + AreaChart: &c, + CatAx: catAx, + ValAx: valAx, + }, + "area3D": { + Area3DChart: &c, + CatAx: catAx, + ValAx: valAx, + }, + "area3DStacked": { + Area3DChart: &c, + CatAx: catAx, + ValAx: valAx, + }, + "area3DPercentStacked": { + Area3DChart: &c, + CatAx: catAx, + ValAx: valAx, + }, + "bar": { + BarChart: &c, + CatAx: catAx, + ValAx: valAx, + }, + "barStacked": { + BarChart: &c, + CatAx: catAx, + ValAx: valAx, + }, + "barPercentStacked": { + BarChart: &c, + CatAx: catAx, + ValAx: valAx, + }, + "bar3DClustered": { + Bar3DChart: &c, + CatAx: catAx, + ValAx: valAx, + }, + "bar3DStacked": { + Bar3DChart: &c, + CatAx: catAx, + ValAx: valAx, + }, + "bar3DPercentStacked": { + Bar3DChart: &c, + CatAx: catAx, + ValAx: valAx, + }, + "col": { + BarChart: &c, + CatAx: catAx, + ValAx: valAx, + }, + "colStacked": { + BarChart: &c, + CatAx: catAx, + ValAx: valAx, + }, + "colPercentStacked": { + BarChart: &c, + CatAx: catAx, + ValAx: valAx, + }, + "col3DClustered": { + Bar3DChart: &c, + CatAx: catAx, + ValAx: valAx, + }, + "col3D": { + Bar3DChart: &c, + CatAx: catAx, + ValAx: valAx, + }, + "col3DStacked": { + Bar3DChart: &c, + CatAx: catAx, + ValAx: valAx, + }, + "col3DPercentStacked": { + Bar3DChart: &c, + CatAx: catAx, + ValAx: valAx, + }, + } + return charts[formatSet.Type] +} + +// drawDoughnutChart provides a function to draw the c:plotArea element for +// doughnut chart by given format sets. +func (f *File) drawDoughnutChart(formatSet *formatChart) *cPlotArea { + return &cPlotArea{ + DoughnutChart: &cCharts{ + VaryColors: &attrValBool{ + Val: true, + }, + Ser: f.drawChartSeries(formatSet), + HoleSize: &attrValInt{Val: 75}, + }, + } +} + +// drawLineChart provides a function to draw the c:plotArea element for line +// chart by given format sets. +func (f *File) drawLineChart(formatSet *formatChart) *cPlotArea { + return &cPlotArea{ + LineChart: &cCharts{ + Grouping: &attrValString{ + Val: plotAreaChartGrouping[formatSet.Type], + }, + VaryColors: &attrValBool{ + Val: false, + }, + Ser: f.drawChartSeries(formatSet), + DLbls: f.drawChartDLbls(formatSet), + Smooth: &attrValBool{ + Val: false, + }, + AxID: []*attrValInt{ + {Val: 754001152}, + {Val: 753999904}, + }, + }, + CatAx: f.drawPlotAreaCatAx(formatSet), + ValAx: f.drawPlotAreaValAx(formatSet), + } +} + +// drawPieChart provides a function to draw the c:plotArea element for pie +// chart by given format sets. +func (f *File) drawPieChart(formatSet *formatChart) *cPlotArea { + return &cPlotArea{ + PieChart: &cCharts{ + VaryColors: &attrValBool{ + Val: true, + }, + Ser: f.drawChartSeries(formatSet), + }, + } +} + +// drawPie3DChart provides a function to draw the c:plotArea element for 3D +// pie chart by given format sets. +func (f *File) drawPie3DChart(formatSet *formatChart) *cPlotArea { + return &cPlotArea{ + Pie3DChart: &cCharts{ + VaryColors: &attrValBool{ + Val: true, + }, + Ser: f.drawChartSeries(formatSet), + }, + } +} + +// drawRadarChart provides a function to draw the c:plotArea element for radar +// chart by given format sets. +func (f *File) drawRadarChart(formatSet *formatChart) *cPlotArea { + return &cPlotArea{ + RadarChart: &cCharts{ + RadarStyle: &attrValString{ + Val: "marker", + }, + VaryColors: &attrValBool{ + Val: false, + }, + Ser: f.drawChartSeries(formatSet), + DLbls: f.drawChartDLbls(formatSet), + AxID: []*attrValInt{ + {Val: 754001152}, + {Val: 753999904}, + }, + }, + CatAx: f.drawPlotAreaCatAx(formatSet), + ValAx: f.drawPlotAreaValAx(formatSet), + } +} + +// drawScatterChart provides a function to draw the c:plotArea element for +// scatter chart by given format sets. +func (f *File) drawScatterChart(formatSet *formatChart) *cPlotArea { + return &cPlotArea{ + ScatterChart: &cCharts{ + ScatterStyle: &attrValString{ + Val: "smoothMarker", // line,lineMarker,marker,none,smooth,smoothMarker + }, + VaryColors: &attrValBool{ + Val: false, + }, + Ser: f.drawChartSeries(formatSet), + DLbls: f.drawChartDLbls(formatSet), + AxID: []*attrValInt{ + {Val: 754001152}, + {Val: 753999904}, + }, + }, + CatAx: f.drawPlotAreaCatAx(formatSet), + ValAx: f.drawPlotAreaValAx(formatSet), + } +} + +// drawChartSeries provides a function to draw the c:ser element by given +// format sets. +func (f *File) drawChartSeries(formatSet *formatChart) *[]cSer { + ser := []cSer{} + for k := range formatSet.Series { + ser = append(ser, cSer{ + IDx: &attrValInt{Val: k}, + Order: &attrValInt{Val: k}, + Tx: &cTx{ + StrRef: &cStrRef{ + F: formatSet.Series[k].Name, + }, + }, + SpPr: f.drawChartSeriesSpPr(k, formatSet), + Marker: f.drawChartSeriesMarker(k, formatSet), + DPt: f.drawChartSeriesDPt(k, formatSet), + DLbls: f.drawChartSeriesDLbls(formatSet), + Cat: f.drawChartSeriesCat(formatSet.Series[k], formatSet), + Val: f.drawChartSeriesVal(formatSet.Series[k], formatSet), + XVal: f.drawChartSeriesXVal(formatSet.Series[k], formatSet), + YVal: f.drawChartSeriesYVal(formatSet.Series[k], formatSet), + }) + } + return &ser +} + +// drawChartSeriesSpPr provides a function to draw the c:spPr element by given +// format sets. +func (f *File) drawChartSeriesSpPr(i int, formatSet *formatChart) *cSpPr { + spPrScatter := &cSpPr{ + Ln: &aLn{ + W: 25400, + NoFill: " ", + }, + } + spPrLine := &cSpPr{ + Ln: &aLn{ + W: 25400, + Cap: "rnd", // rnd, sq, flat + SolidFill: &aSolidFill{ + SchemeClr: &aSchemeClr{Val: "accent" + strconv.Itoa(i+1)}, + }, + }, + } + chartSeriesSpPr := map[string]*cSpPr{Area: nil, AreaStacked: nil, AreaPercentStacked: nil, Area3D: nil, Area3DStacked: nil, Area3DPercentStacked: nil, Bar: nil, BarStacked: nil, BarPercentStacked: nil, Bar3DClustered: nil, Bar3DStacked: nil, Bar3DPercentStacked: nil, Col: nil, ColStacked: nil, ColPercentStacked: nil, Col3DClustered: nil, Col3D: nil, Col3DStacked: nil, Col3DPercentStacked: nil, Doughnut: nil, Line: spPrLine, Pie: nil, Pie3D: nil, Radar: nil, Scatter: spPrScatter} + return chartSeriesSpPr[formatSet.Type] +} + +// drawChartSeriesDPt provides a function to draw the c:dPt element by given +// data index and format sets. +func (f *File) drawChartSeriesDPt(i int, formatSet *formatChart) []*cDPt { + dpt := []*cDPt{{ + IDx: &attrValInt{Val: i}, + Bubble3D: &attrValBool{Val: false}, + SpPr: &cSpPr{ + SolidFill: &aSolidFill{ + SchemeClr: &aSchemeClr{Val: "accent" + strconv.Itoa(i+1)}, + }, + Ln: &aLn{ + W: 25400, + Cap: "rnd", + SolidFill: &aSolidFill{ + SchemeClr: &aSchemeClr{Val: "lt" + strconv.Itoa(i+1)}, + }, + }, + Sp3D: &aSp3D{ + ContourW: 25400, + ContourClr: &aContourClr{ + SchemeClr: &aSchemeClr{Val: "lt" + strconv.Itoa(i+1)}, + }, + }, + }, + }} + chartSeriesDPt := map[string][]*cDPt{Area: nil, AreaStacked: nil, AreaPercentStacked: nil, Area3D: nil, Area3DStacked: nil, Area3DPercentStacked: nil, Bar: nil, BarStacked: nil, BarPercentStacked: nil, Bar3DClustered: nil, Bar3DStacked: nil, Bar3DPercentStacked: nil, Col: nil, ColStacked: nil, ColPercentStacked: nil, Col3DClustered: nil, Col3D: nil, Col3DStacked: nil, Col3DPercentStacked: nil, Doughnut: nil, Line: nil, Pie: dpt, Pie3D: dpt, Radar: nil, Scatter: nil} + return chartSeriesDPt[formatSet.Type] +} + +// drawChartSeriesCat provides a function to draw the c:cat element by given +// chart series and format sets. +func (f *File) drawChartSeriesCat(v formatChartSeries, formatSet *formatChart) *cCat { + cat := &cCat{ + StrRef: &cStrRef{ + F: v.Categories, + }, + } + chartSeriesCat := map[string]*cCat{Area: cat, AreaStacked: cat, AreaPercentStacked: cat, Area3D: cat, Area3DStacked: cat, Area3DPercentStacked: cat, Bar: cat, BarStacked: cat, BarPercentStacked: cat, Bar3DClustered: cat, Bar3DStacked: cat, Bar3DPercentStacked: cat, Col: cat, ColStacked: cat, ColPercentStacked: cat, Col3DClustered: cat, Col3D: cat, Col3DStacked: cat, Col3DPercentStacked: cat, Doughnut: cat, Line: cat, Pie: cat, Pie3D: cat, Radar: cat, Scatter: nil} + return chartSeriesCat[formatSet.Type] +} + +// drawChartSeriesVal provides a function to draw the c:val element by given +// chart series and format sets. +func (f *File) drawChartSeriesVal(v formatChartSeries, formatSet *formatChart) *cVal { + val := &cVal{ + NumRef: &cNumRef{ + F: v.Values, + }, + } + chartSeriesVal := map[string]*cVal{Area: val, AreaStacked: val, AreaPercentStacked: val, Area3D: val, Area3DStacked: val, Area3DPercentStacked: val, Bar: val, BarStacked: val, BarPercentStacked: val, Bar3DClustered: val, Bar3DStacked: val, Bar3DPercentStacked: val, Col: val, ColStacked: val, ColPercentStacked: val, Col3DClustered: val, Col3D: val, Col3DStacked: val, Col3DPercentStacked: val, Doughnut: val, Line: val, Pie: val, Pie3D: val, Radar: val, Scatter: nil} + return chartSeriesVal[formatSet.Type] +} + +// drawChartSeriesMarker provides a function to draw the c:marker element by +// given data index and format sets. +func (f *File) drawChartSeriesMarker(i int, formatSet *formatChart) *cMarker { + marker := &cMarker{ + Symbol: &attrValString{Val: "circle"}, + Size: &attrValInt{Val: 5}, + SpPr: &cSpPr{ + SolidFill: &aSolidFill{ + SchemeClr: &aSchemeClr{ + Val: "accent" + strconv.Itoa(i+1), + }, + }, + Ln: &aLn{ + W: 9252, + SolidFill: &aSolidFill{ + SchemeClr: &aSchemeClr{ + Val: "accent" + strconv.Itoa(i+1), + }, + }, + }, + }, + } + chartSeriesMarker := map[string]*cMarker{Area: nil, AreaStacked: nil, AreaPercentStacked: nil, Area3D: nil, Area3DStacked: nil, Area3DPercentStacked: nil, Bar: nil, BarStacked: nil, BarPercentStacked: nil, Bar3DClustered: nil, Bar3DStacked: nil, Bar3DPercentStacked: nil, Col: nil, ColStacked: nil, ColPercentStacked: nil, Col3DClustered: nil, Col3D: nil, Col3DStacked: nil, Col3DPercentStacked: nil, Doughnut: nil, Line: nil, Pie: nil, Pie3D: nil, Radar: nil, Scatter: marker} + return chartSeriesMarker[formatSet.Type] +} + +// drawChartSeriesXVal provides a function to draw the c:xVal element by given +// chart series and format sets. +func (f *File) drawChartSeriesXVal(v formatChartSeries, formatSet *formatChart) *cCat { + cat := &cCat{ + StrRef: &cStrRef{ + F: v.Categories, + }, + } + chartSeriesXVal := map[string]*cCat{Area: nil, AreaStacked: nil, AreaPercentStacked: nil, Area3D: nil, Area3DStacked: nil, Area3DPercentStacked: nil, Bar: nil, BarStacked: nil, BarPercentStacked: nil, Bar3DClustered: nil, Bar3DStacked: nil, Bar3DPercentStacked: nil, Col: nil, ColStacked: nil, ColPercentStacked: nil, Col3DClustered: nil, Col3D: nil, Col3DStacked: nil, Col3DPercentStacked: nil, Doughnut: nil, Line: nil, Pie: nil, Pie3D: nil, Radar: nil, Scatter: cat} + return chartSeriesXVal[formatSet.Type] +} + +// drawChartSeriesYVal provides a function to draw the c:yVal element by given +// chart series and format sets. +func (f *File) drawChartSeriesYVal(v formatChartSeries, formatSet *formatChart) *cVal { + val := &cVal{ + NumRef: &cNumRef{ + F: v.Values, + }, + } + chartSeriesYVal := map[string]*cVal{Area: nil, AreaStacked: nil, AreaPercentStacked: nil, Area3D: nil, Area3DStacked: nil, Area3DPercentStacked: nil, Bar: nil, BarStacked: nil, BarPercentStacked: nil, Bar3DClustered: nil, Bar3DStacked: nil, Bar3DPercentStacked: nil, Col: nil, ColStacked: nil, ColPercentStacked: nil, Col3DClustered: nil, Col3D: nil, Col3DStacked: nil, Col3DPercentStacked: nil, Doughnut: nil, Line: nil, Pie: nil, Pie3D: nil, Radar: nil, Scatter: val} + return chartSeriesYVal[formatSet.Type] +} + +// drawChartDLbls provides a function to draw the c:dLbls element by given +// format sets. +func (f *File) drawChartDLbls(formatSet *formatChart) *cDLbls { + return &cDLbls{ + ShowLegendKey: &attrValBool{Val: formatSet.Legend.ShowLegendKey}, + ShowVal: &attrValBool{Val: formatSet.Plotarea.ShowVal}, + ShowCatName: &attrValBool{Val: formatSet.Plotarea.ShowCatName}, + ShowSerName: &attrValBool{Val: formatSet.Plotarea.ShowSerName}, + ShowBubbleSize: &attrValBool{Val: formatSet.Plotarea.ShowBubbleSize}, + ShowPercent: &attrValBool{Val: formatSet.Plotarea.ShowPercent}, + ShowLeaderLines: &attrValBool{Val: formatSet.Plotarea.ShowLeaderLines}, + } +} + +// drawChartSeriesDLbls provides a function to draw the c:dLbls element by +// given format sets. +func (f *File) drawChartSeriesDLbls(formatSet *formatChart) *cDLbls { + dLbls := f.drawChartDLbls(formatSet) + chartSeriesDLbls := map[string]*cDLbls{Area: dLbls, AreaStacked: dLbls, AreaPercentStacked: dLbls, Area3D: dLbls, Area3DStacked: dLbls, Area3DPercentStacked: dLbls, Bar: dLbls, BarStacked: dLbls, BarPercentStacked: dLbls, Bar3DClustered: dLbls, Bar3DStacked: dLbls, Bar3DPercentStacked: dLbls, Col: dLbls, ColStacked: dLbls, ColPercentStacked: dLbls, Col3DClustered: dLbls, Col3D: dLbls, Col3DStacked: dLbls, Col3DPercentStacked: dLbls, Doughnut: dLbls, Line: dLbls, Pie: dLbls, Pie3D: dLbls, Radar: dLbls, Scatter: nil} + return chartSeriesDLbls[formatSet.Type] +} + +// drawPlotAreaCatAx provides a function to draw the c:catAx element. +func (f *File) drawPlotAreaCatAx(formatSet *formatChart) []*cAxs { + min := &attrValFloat{Val: formatSet.XAxis.Minimum} + max := &attrValFloat{Val: formatSet.XAxis.Maximum} + if formatSet.XAxis.Minimum == 0 { + min = nil + } + if formatSet.XAxis.Maximum == 0 { + max = nil + } + return []*cAxs{ + { + AxID: &attrValInt{Val: 754001152}, + Scaling: &cScaling{ + Orientation: &attrValString{Val: orientation[formatSet.XAxis.ReverseOrder]}, + Max: max, + Min: min, + }, + Delete: &attrValBool{Val: false}, + AxPos: &attrValString{Val: catAxPos[formatSet.XAxis.ReverseOrder]}, + NumFmt: &cNumFmt{ + FormatCode: "General", + SourceLinked: true, + }, + MajorTickMark: &attrValString{Val: "none"}, + MinorTickMark: &attrValString{Val: "none"}, + TickLblPos: &attrValString{Val: "nextTo"}, + SpPr: f.drawPlotAreaSpPr(), + TxPr: f.drawPlotAreaTxPr(), + CrossAx: &attrValInt{Val: 753999904}, + Crosses: &attrValString{Val: "autoZero"}, + Auto: &attrValBool{Val: true}, + LblAlgn: &attrValString{Val: "ctr"}, + LblOffset: &attrValInt{Val: 100}, + NoMultiLvlLbl: &attrValBool{Val: false}, + }, + } +} + +// drawPlotAreaValAx provides a function to draw the c:valAx element. +func (f *File) drawPlotAreaValAx(formatSet *formatChart) []*cAxs { + min := &attrValFloat{Val: formatSet.YAxis.Minimum} + max := &attrValFloat{Val: formatSet.YAxis.Maximum} + if formatSet.YAxis.Minimum == 0 { + min = nil + } + if formatSet.YAxis.Maximum == 0 { + max = nil + } + return []*cAxs{ + { + AxID: &attrValInt{Val: 753999904}, + Scaling: &cScaling{ + Orientation: &attrValString{Val: orientation[formatSet.YAxis.ReverseOrder]}, + Max: max, + Min: min, + }, + Delete: &attrValBool{Val: false}, + AxPos: &attrValString{Val: valAxPos[formatSet.YAxis.ReverseOrder]}, + NumFmt: &cNumFmt{ + FormatCode: chartValAxNumFmtFormatCode[formatSet.Type], + SourceLinked: true, + }, + MajorTickMark: &attrValString{Val: "none"}, + MinorTickMark: &attrValString{Val: "none"}, + TickLblPos: &attrValString{Val: "nextTo"}, + SpPr: f.drawPlotAreaSpPr(), + TxPr: f.drawPlotAreaTxPr(), + CrossAx: &attrValInt{Val: 754001152}, + Crosses: &attrValString{Val: "autoZero"}, + CrossBetween: &attrValString{Val: chartValAxCrossBetween[formatSet.Type]}, + }, + } +} + +// drawPlotAreaSpPr provides a function to draw the c:spPr element. +func (f *File) drawPlotAreaSpPr() *cSpPr { + return &cSpPr{ + Ln: &aLn{ + W: 9525, + Cap: "flat", + Cmpd: "sng", + Algn: "ctr", + SolidFill: &aSolidFill{ + SchemeClr: &aSchemeClr{ + Val: "tx1", + LumMod: &attrValInt{Val: 15000}, + LumOff: &attrValInt{Val: 85000}, + }, + }, + }, + } +} + +// drawPlotAreaTxPr provides a function to draw the c:txPr element. +func (f *File) drawPlotAreaTxPr() *cTxPr { + return &cTxPr{ + BodyPr: aBodyPr{ + Rot: -60000000, + SpcFirstLastPara: true, + VertOverflow: "ellipsis", + Vert: "horz", + Wrap: "square", + Anchor: "ctr", + AnchorCtr: true, + }, + P: aP{ + PPr: &aPPr{ + DefRPr: aRPr{ + Sz: 900, + B: false, + I: false, + U: "none", + Strike: "noStrike", + Kern: 1200, + Baseline: 0, + SolidFill: &aSolidFill{ + SchemeClr: &aSchemeClr{ + Val: "tx1", + LumMod: &attrValInt{Val: 15000}, + LumOff: &attrValInt{Val: 85000}, + }, + }, + Latin: &aLatin{Typeface: "+mn-lt"}, + Ea: &aEa{Typeface: "+mn-ea"}, + Cs: &aCs{Typeface: "+mn-cs"}, + }, + }, + EndParaRPr: &aEndParaRPr{Lang: "en-US"}, + }, + } +} + +// drawingParser provides a function to parse drawingXML. In order to solve +// the problem that the label structure is changed after serialization and +// deserialization, two different structures: decodeWsDr and encodeWsDr are +// defined. +func (f *File) drawingParser(drawingXML string, content *xlsxWsDr) int { + cNvPrID := 1 + _, ok := f.XLSX[drawingXML] + if ok { // Append Model + decodeWsDr := decodeWsDr{} + _ = xml.Unmarshal(namespaceStrictToTransitional(f.readXML(drawingXML)), &decodeWsDr) + content.R = decodeWsDr.R + cNvPrID = len(decodeWsDr.OneCellAnchor) + len(decodeWsDr.TwoCellAnchor) + 1 + for _, v := range decodeWsDr.OneCellAnchor { + content.OneCellAnchor = append(content.OneCellAnchor, &xdrCellAnchor{ + EditAs: v.EditAs, + GraphicFrame: v.Content, + }) + } + for _, v := range decodeWsDr.TwoCellAnchor { + content.TwoCellAnchor = append(content.TwoCellAnchor, &xdrCellAnchor{ + EditAs: v.EditAs, + GraphicFrame: v.Content, + }) + } + } + return cNvPrID +} + +// addDrawingChart provides a function to add chart graphic frame by given +// sheet, drawingXML, cell, width, height, relationship index and format sets. +func (f *File) addDrawingChart(sheet, drawingXML, cell string, width, height, rID int, formatSet *formatPicture) { + cell = strings.ToUpper(cell) + fromCol := string(strings.Map(letterOnlyMapF, cell)) + fromRow, _ := strconv.Atoi(strings.Map(intOnlyMapF, cell)) + row := fromRow - 1 + col := TitleToNumber(fromCol) + width = int(float64(width) * formatSet.XScale) + height = int(float64(height) * formatSet.YScale) + colStart, rowStart, _, _, colEnd, rowEnd, x2, y2 := f.positionObjectPixels(sheet, col, row, formatSet.OffsetX, formatSet.OffsetY, width, height) + content := xlsxWsDr{} + content.A = NameSpaceDrawingML + content.Xdr = NameSpaceDrawingMLSpreadSheet + cNvPrID := f.drawingParser(drawingXML, &content) + twoCellAnchor := xdrCellAnchor{} + twoCellAnchor.EditAs = formatSet.Positioning + from := xlsxFrom{} + from.Col = colStart + from.ColOff = formatSet.OffsetX * EMU + from.Row = rowStart + from.RowOff = formatSet.OffsetY * EMU + to := xlsxTo{} + to.Col = colEnd + to.ColOff = x2 * EMU + to.Row = rowEnd + to.RowOff = y2 * EMU + twoCellAnchor.From = &from + twoCellAnchor.To = &to + + graphicFrame := xlsxGraphicFrame{ + NvGraphicFramePr: xlsxNvGraphicFramePr{ + CNvPr: &xlsxCNvPr{ + ID: f.countCharts() + f.countMedia() + 1, + Name: "Chart " + strconv.Itoa(cNvPrID), + }, + }, + Graphic: &xlsxGraphic{ + GraphicData: &xlsxGraphicData{ + URI: NameSpaceDrawingMLChart, + Chart: &xlsxChart{ + C: NameSpaceDrawingMLChart, + R: SourceRelationship, + RID: "rId" + strconv.Itoa(rID), + }, + }, + }, + } + graphic, _ := xml.Marshal(graphicFrame) + twoCellAnchor.GraphicFrame = string(graphic) + twoCellAnchor.ClientData = &xdrClientData{ + FLocksWithSheet: formatSet.FLocksWithSheet, + FPrintsWithSheet: formatSet.FPrintsWithSheet, + } + content.TwoCellAnchor = append(content.TwoCellAnchor, &twoCellAnchor) + output, _ := xml.Marshal(content) + f.saveFileList(drawingXML, output) +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/codelingo.yaml b/vendor/github.com/360EntSecGroup-Skylar/excelize/codelingo.yaml new file mode 100644 index 0000000000..dfe344b471 --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/codelingo.yaml @@ -0,0 +1,3 @@ +tenets: + - import: codelingo/effective-go + - import: codelingo/code-review-comments diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/col.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/col.go new file mode 100644 index 0000000000..af2c321347 --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/col.go @@ -0,0 +1,376 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. + +package excelize + +import ( + "bytes" + "math" + "strconv" + "strings" +) + +// Define the default cell size and EMU unit of measurement. +const ( + defaultColWidthPixels float64 = 64 + defaultRowHeightPixels float64 = 20 + EMU int = 9525 +) + +// GetColVisible provides a function to get visible of a single column by given +// worksheet name and column name. For example, get visible state of column D +// in Sheet1: +// +// xlsx.GetColVisible("Sheet1", "D") +// +func (f *File) GetColVisible(sheet, column string) bool { + xlsx := f.workSheetReader(sheet) + col := TitleToNumber(strings.ToUpper(column)) + 1 + visible := true + if xlsx.Cols == nil { + return visible + } + for c := range xlsx.Cols.Col { + if xlsx.Cols.Col[c].Min <= col && col <= xlsx.Cols.Col[c].Max { + visible = !xlsx.Cols.Col[c].Hidden + } + } + return visible +} + +// SetColVisible provides a function to set visible of a single column by given +// worksheet name and column name. For example, hide column D in Sheet1: +// +// xlsx.SetColVisible("Sheet1", "D", false) +// +func (f *File) SetColVisible(sheet, column string, visible bool) { + xlsx := f.workSheetReader(sheet) + c := TitleToNumber(strings.ToUpper(column)) + 1 + col := xlsxCol{ + Min: c, + Max: c, + Hidden: !visible, + CustomWidth: true, + } + if xlsx.Cols == nil { + cols := xlsxCols{} + cols.Col = append(cols.Col, col) + xlsx.Cols = &cols + return + } + for v := range xlsx.Cols.Col { + if xlsx.Cols.Col[v].Min <= c && c <= xlsx.Cols.Col[v].Max { + col = xlsx.Cols.Col[v] + } + } + col.Min = c + col.Max = c + col.Hidden = !visible + col.CustomWidth = true + xlsx.Cols.Col = append(xlsx.Cols.Col, col) +} + +// GetColOutlineLevel provides a function to get outline level of a single +// column by given worksheet name and column name. For example, get outline +// level of column D in Sheet1: +// +// xlsx.GetColOutlineLevel("Sheet1", "D") +// +func (f *File) GetColOutlineLevel(sheet, column string) uint8 { + xlsx := f.workSheetReader(sheet) + col := TitleToNumber(strings.ToUpper(column)) + 1 + level := uint8(0) + if xlsx.Cols == nil { + return level + } + for c := range xlsx.Cols.Col { + if xlsx.Cols.Col[c].Min <= col && col <= xlsx.Cols.Col[c].Max { + level = xlsx.Cols.Col[c].OutlineLevel + } + } + return level +} + +// SetColOutlineLevel provides a function to set outline level of a single +// column by given worksheet name and column name. For example, set outline +// level of column D in Sheet1 to 2: +// +// xlsx.SetColOutlineLevel("Sheet1", "D", 2) +// +func (f *File) SetColOutlineLevel(sheet, column string, level uint8) { + xlsx := f.workSheetReader(sheet) + c := TitleToNumber(strings.ToUpper(column)) + 1 + col := xlsxCol{ + Min: c, + Max: c, + OutlineLevel: level, + CustomWidth: true, + } + if xlsx.Cols == nil { + cols := xlsxCols{} + cols.Col = append(cols.Col, col) + xlsx.Cols = &cols + return + } + for v := range xlsx.Cols.Col { + if xlsx.Cols.Col[v].Min <= c && c <= xlsx.Cols.Col[v].Max { + col = xlsx.Cols.Col[v] + } + } + col.Min = c + col.Max = c + col.OutlineLevel = level + col.CustomWidth = true + xlsx.Cols.Col = append(xlsx.Cols.Col, col) +} + +// SetColWidth provides a function to set the width of a single column or +// multiple columns. For example: +// +// xlsx := excelize.NewFile() +// xlsx.SetColWidth("Sheet1", "A", "H", 20) +// err := xlsx.Save() +// if err != nil { +// fmt.Println(err) +// } +// +func (f *File) SetColWidth(sheet, startcol, endcol string, width float64) { + min := TitleToNumber(strings.ToUpper(startcol)) + 1 + max := TitleToNumber(strings.ToUpper(endcol)) + 1 + if min > max { + min, max = max, min + } + xlsx := f.workSheetReader(sheet) + col := xlsxCol{ + Min: min, + Max: max, + Width: width, + CustomWidth: true, + } + if xlsx.Cols != nil { + xlsx.Cols.Col = append(xlsx.Cols.Col, col) + } else { + cols := xlsxCols{} + cols.Col = append(cols.Col, col) + xlsx.Cols = &cols + } +} + +// positionObjectPixels calculate the vertices that define the position of a +// graphical object within the worksheet in pixels. +// +// +------------+------------+ +// | A | B | +// +-----+------------+------------+ +// | |(x1,y1) | | +// | 1 |(A1)._______|______ | +// | | | | | +// | | | | | +// +-----+----| OBJECT |-----+ +// | | | | | +// | 2 | |______________. | +// | | | (B2)| +// | | | (x2,y2)| +// +-----+------------+------------+ +// +// Example of an object that covers some of the area from cell A1 to B2. +// +// Based on the width and height of the object we need to calculate 8 vars: +// +// colStart, rowStart, colEnd, rowEnd, x1, y1, x2, y2. +// +// We also calculate the absolute x and y position of the top left vertex of +// the object. This is required for images. +// +// The width and height of the cells that the object occupies can be +// variable and have to be taken into account. +// +// The values of col_start and row_start are passed in from the calling +// function. The values of col_end and row_end are calculated by +// subtracting the width and height of the object from the width and +// height of the underlying cells. +// +// colStart # Col containing upper left corner of object. +// x1 # Distance to left side of object. +// +// rowStart # Row containing top left corner of object. +// y1 # Distance to top of object. +// +// colEnd # Col containing lower right corner of object. +// x2 # Distance to right side of object. +// +// rowEnd # Row containing bottom right corner of object. +// y2 # Distance to bottom of object. +// +// width # Width of object frame. +// height # Height of object frame. +// +// xAbs # Absolute distance to left side of object. +// yAbs # Absolute distance to top side of object. +// +func (f *File) positionObjectPixels(sheet string, colStart, rowStart, x1, y1, width, height int) (int, int, int, int, int, int, int, int) { + xAbs := 0 + yAbs := 0 + + // Calculate the absolute x offset of the top-left vertex. + for colID := 1; colID <= colStart; colID++ { + xAbs += f.getColWidth(sheet, colID) + } + xAbs += x1 + + // Calculate the absolute y offset of the top-left vertex. + // Store the column change to allow optimisations. + for rowID := 1; rowID <= rowStart; rowID++ { + yAbs += f.getRowHeight(sheet, rowID) + } + yAbs += y1 + + // Adjust start column for offsets that are greater than the col width. + for x1 >= f.getColWidth(sheet, colStart) { + x1 -= f.getColWidth(sheet, colStart) + colStart++ + } + + // Adjust start row for offsets that are greater than the row height. + for y1 >= f.getRowHeight(sheet, rowStart) { + y1 -= f.getRowHeight(sheet, rowStart) + rowStart++ + } + + // Initialise end cell to the same as the start cell. + colEnd := colStart + rowEnd := rowStart + + width += x1 + height += y1 + + // Subtract the underlying cell widths to find end cell of the object. + for width >= f.getColWidth(sheet, colEnd) { + colEnd++ + width -= f.getColWidth(sheet, colEnd) + } + + // Subtract the underlying cell heights to find end cell of the object. + for height >= f.getRowHeight(sheet, rowEnd) { + rowEnd++ + height -= f.getRowHeight(sheet, rowEnd) + } + + // The end vertices are whatever is left from the width and height. + x2 := width + y2 := height + return colStart, rowStart, xAbs, yAbs, colEnd, rowEnd, x2, y2 +} + +// getColWidth provides a function to get column width in pixels by given +// sheet name and column index. +func (f *File) getColWidth(sheet string, col int) int { + xlsx := f.workSheetReader(sheet) + if xlsx.Cols != nil { + var width float64 + for _, v := range xlsx.Cols.Col { + if v.Min <= col && col <= v.Max { + width = v.Width + } + } + if width != 0 { + return int(convertColWidthToPixels(width)) + } + } + // Optimisation for when the column widths haven't changed. + return int(defaultColWidthPixels) +} + +// GetColWidth provides a function to get column width by given worksheet name +// and column index. +func (f *File) GetColWidth(sheet, column string) float64 { + col := TitleToNumber(strings.ToUpper(column)) + 1 + xlsx := f.workSheetReader(sheet) + if xlsx.Cols != nil { + var width float64 + for _, v := range xlsx.Cols.Col { + if v.Min <= col && col <= v.Max { + width = v.Width + } + } + if width != 0 { + return width + } + } + // Optimisation for when the column widths haven't changed. + return defaultColWidthPixels +} + +// InsertCol provides a function to insert a new column before given column +// index. For example, create a new column before column C in Sheet1: +// +// xlsx.InsertCol("Sheet1", "C") +// +func (f *File) InsertCol(sheet, column string) { + col := TitleToNumber(strings.ToUpper(column)) + f.adjustHelper(sheet, col, -1, 1) +} + +// RemoveCol provides a function to remove single column by given worksheet +// name and column index. For example, remove column C in Sheet1: +// +// xlsx.RemoveCol("Sheet1", "C") +// +func (f *File) RemoveCol(sheet, column string) { + xlsx := f.workSheetReader(sheet) + for r := range xlsx.SheetData.Row { + for k, v := range xlsx.SheetData.Row[r].C { + axis := v.R + col := string(strings.Map(letterOnlyMapF, axis)) + if col == column { + xlsx.SheetData.Row[r].C = append(xlsx.SheetData.Row[r].C[:k], xlsx.SheetData.Row[r].C[k+1:]...) + } + } + } + col := TitleToNumber(strings.ToUpper(column)) + f.adjustHelper(sheet, col, -1, -1) +} + +// completeCol provieds function to completion column element tags of XML in a +// sheet. +func completeCol(xlsx *xlsxWorksheet, row, cell int) { + buffer := bytes.Buffer{} + for r := range xlsx.SheetData.Row { + if len(xlsx.SheetData.Row[r].C) < cell { + start := len(xlsx.SheetData.Row[r].C) + for iii := start; iii < cell; iii++ { + buffer.WriteString(ToAlphaString(iii)) + buffer.WriteString(strconv.Itoa(r + 1)) + xlsx.SheetData.Row[r].C = append(xlsx.SheetData.Row[r].C, xlsxC{ + R: buffer.String(), + }) + buffer.Reset() + } + } + } +} + +// convertColWidthToPixels provieds function to convert the width of a cell +// from user's units to pixels. Excel rounds the column width to the nearest +// pixel. If the width hasn't been set by the user we use the default value. +// If the column is hidden it has a value of zero. +func convertColWidthToPixels(width float64) float64 { + var padding float64 = 5 + var pixels float64 + var maxDigitWidth float64 = 7 + if width == 0 { + return pixels + } + if width < 1 { + pixels = (width * 12) + 0.5 + return math.Ceil(pixels) + } + pixels = (width*maxDigitWidth + 0.5) + padding + return math.Ceil(pixels) +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/comment.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/comment.go new file mode 100644 index 0000000000..07f70b5088 --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/comment.go @@ -0,0 +1,273 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. + +package excelize + +import ( + "encoding/json" + "encoding/xml" + "fmt" + "strconv" + "strings" +) + +// parseFormatCommentsSet provides a function to parse the format settings of +// the comment with default value. +func parseFormatCommentsSet(formatSet string) (*formatComment, error) { + format := formatComment{ + Author: "Author:", + Text: " ", + } + err := json.Unmarshal([]byte(formatSet), &format) + return &format, err +} + +// GetComments retrieves all comments and returns a map of worksheet name to +// the worksheet comments. +func (f *File) GetComments() (comments map[string][]Comment) { + comments = map[string][]Comment{} + for n := range f.sheetMap { + commentID := f.GetSheetIndex(n) + commentsXML := "xl/comments" + strconv.Itoa(commentID) + ".xml" + c, ok := f.XLSX[commentsXML] + if ok { + d := xlsxComments{} + xml.Unmarshal([]byte(c), &d) + sheetComments := []Comment{} + for _, comment := range d.CommentList.Comment { + sheetComment := Comment{} + if comment.AuthorID < len(d.Authors) { + sheetComment.Author = d.Authors[comment.AuthorID].Author + } + sheetComment.Ref = comment.Ref + sheetComment.AuthorID = comment.AuthorID + for _, text := range comment.Text.R { + sheetComment.Text += text.T + } + sheetComments = append(sheetComments, sheetComment) + } + comments[n] = sheetComments + } + } + return +} + +// AddComment provides the method to add comment in a sheet by given worksheet +// index, cell and format set (such as author and text). Note that the max +// author length is 255 and the max text length is 32512. For example, add a +// comment in Sheet1!$A$30: +// +// xlsx.AddComment("Sheet1", "A30", `{"author":"Excelize: ","text":"This is a comment."}`) +// +func (f *File) AddComment(sheet, cell, format string) error { + formatSet, err := parseFormatCommentsSet(format) + if err != nil { + return err + } + // Read sheet data. + xlsx := f.workSheetReader(sheet) + commentID := f.countComments() + 1 + drawingVML := "xl/drawings/vmlDrawing" + strconv.Itoa(commentID) + ".vml" + sheetRelationshipsComments := "../comments" + strconv.Itoa(commentID) + ".xml" + sheetRelationshipsDrawingVML := "../drawings/vmlDrawing" + strconv.Itoa(commentID) + ".vml" + if xlsx.LegacyDrawing != nil { + // The worksheet already has a comments relationships, use the relationships drawing ../drawings/vmlDrawing%d.vml. + sheetRelationshipsDrawingVML = f.getSheetRelationshipsTargetByID(sheet, xlsx.LegacyDrawing.RID) + commentID, _ = strconv.Atoi(strings.TrimSuffix(strings.TrimPrefix(sheetRelationshipsDrawingVML, "../drawings/vmlDrawing"), ".vml")) + drawingVML = strings.Replace(sheetRelationshipsDrawingVML, "..", "xl", -1) + } else { + // Add first comment for given sheet. + rID := f.addSheetRelationships(sheet, SourceRelationshipDrawingVML, sheetRelationshipsDrawingVML, "") + f.addSheetRelationships(sheet, SourceRelationshipComments, sheetRelationshipsComments, "") + f.addSheetLegacyDrawing(sheet, rID) + } + commentsXML := "xl/comments" + strconv.Itoa(commentID) + ".xml" + f.addComment(commentsXML, cell, formatSet) + var colCount int + for i, l := range strings.Split(formatSet.Text, "\n") { + if ll := len(l); ll > colCount { + if i == 0 { + ll += len(formatSet.Author) + } + colCount = ll + } + } + f.addDrawingVML(commentID, drawingVML, cell, strings.Count(formatSet.Text, "\n")+1, colCount) + f.addContentTypePart(commentID, "comments") + return err +} + +// addDrawingVML provides a function to create comment as +// xl/drawings/vmlDrawing%d.vml by given commit ID and cell. +func (f *File) addDrawingVML(commentID int, drawingVML, cell string, lineCount, colCount int) { + col := string(strings.Map(letterOnlyMapF, cell)) + row, _ := strconv.Atoi(strings.Map(intOnlyMapF, cell)) + xAxis := row - 1 + yAxis := TitleToNumber(col) + vml := vmlDrawing{ + XMLNSv: "urn:schemas-microsoft-com:vml", + XMLNSo: "urn:schemas-microsoft-com:office:office", + XMLNSx: "urn:schemas-microsoft-com:office:excel", + XMLNSmv: "http://macVmlSchemaUri", + Shapelayout: &xlsxShapelayout{ + Ext: "edit", + IDmap: &xlsxIDmap{ + Ext: "edit", + Data: commentID, + }, + }, + Shapetype: &xlsxShapetype{ + ID: "_x0000_t202", + Coordsize: "21600,21600", + Spt: 202, + Path: "m0,0l0,21600,21600,21600,21600,0xe", + Stroke: &xlsxStroke{ + Joinstyle: "miter", + }, + VPath: &vPath{ + Gradientshapeok: "t", + Connecttype: "miter", + }, + }, + } + sp := encodeShape{ + Fill: &vFill{ + Color2: "#fbfe82", + Angle: -180, + Type: "gradient", + Fill: &oFill{ + Ext: "view", + Type: "gradientUnscaled", + }, + }, + Shadow: &vShadow{ + On: "t", + Color: "black", + Obscured: "t", + }, + Path: &vPath{ + Connecttype: "none", + }, + Textbox: &vTextbox{ + Style: "mso-direction-alt:auto", + Div: &xlsxDiv{ + Style: "text-align:left", + }, + }, + ClientData: &xClientData{ + ObjectType: "Note", + Anchor: fmt.Sprintf( + "%d, 23, %d, 0, %d, %d, %d, 5", + 1+yAxis, 1+xAxis, 2+yAxis+lineCount, colCount+yAxis, 2+xAxis+lineCount), + AutoFill: "True", + Row: xAxis, + Column: yAxis, + }, + } + s, _ := xml.Marshal(sp) + shape := xlsxShape{ + ID: "_x0000_s1025", + Type: "#_x0000_t202", + Style: "position:absolute;73.5pt;width:108pt;height:59.25pt;z-index:1;visibility:hidden", + Fillcolor: "#fbf6d6", + Strokecolor: "#edeaa1", + Val: string(s[13 : len(s)-14]), + } + c, ok := f.XLSX[drawingVML] + if ok { + d := decodeVmlDrawing{} + _ = xml.Unmarshal(namespaceStrictToTransitional(c), &d) + for _, v := range d.Shape { + s := xlsxShape{ + ID: "_x0000_s1025", + Type: "#_x0000_t202", + Style: "position:absolute;73.5pt;width:108pt;height:59.25pt;z-index:1;visibility:hidden", + Fillcolor: "#fbf6d6", + Strokecolor: "#edeaa1", + Val: v.Val, + } + vml.Shape = append(vml.Shape, s) + } + } + vml.Shape = append(vml.Shape, shape) + v, _ := xml.Marshal(vml) + f.XLSX[drawingVML] = v +} + +// addComment provides a function to create chart as xl/comments%d.xml by +// given cell and format sets. +func (f *File) addComment(commentsXML, cell string, formatSet *formatComment) { + a := formatSet.Author + t := formatSet.Text + if len(a) > 255 { + a = a[0:255] + } + if len(t) > 32512 { + t = t[0:32512] + } + comments := xlsxComments{ + Authors: []xlsxAuthor{ + { + Author: formatSet.Author, + }, + }, + } + cmt := xlsxComment{ + Ref: cell, + AuthorID: 0, + Text: xlsxText{ + R: []xlsxR{ + { + RPr: &xlsxRPr{ + B: " ", + Sz: &attrValFloat{Val: 9}, + Color: &xlsxColor{ + Indexed: 81, + }, + RFont: &attrValString{Val: "Calibri"}, + Family: &attrValInt{Val: 2}, + }, + T: a, + }, + { + RPr: &xlsxRPr{ + Sz: &attrValFloat{Val: 9}, + Color: &xlsxColor{ + Indexed: 81, + }, + RFont: &attrValString{Val: "Calibri"}, + Family: &attrValInt{Val: 2}, + }, + T: t, + }, + }, + }, + } + c, ok := f.XLSX[commentsXML] + if ok { + d := xlsxComments{} + _ = xml.Unmarshal(namespaceStrictToTransitional(c), &d) + comments.CommentList.Comment = append(comments.CommentList.Comment, d.CommentList.Comment...) + } + comments.CommentList.Comment = append(comments.CommentList.Comment, cmt) + v, _ := xml.Marshal(comments) + f.saveFileList(commentsXML, v) +} + +// countComments provides a function to get comments files count storage in +// the folder xl. +func (f *File) countComments() int { + count := 0 + for k := range f.XLSX { + if strings.Contains(k, "xl/comments") { + count++ + } + } + return count +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/datavalidation.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/datavalidation.go new file mode 100644 index 0000000000..0a95251b82 --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/datavalidation.go @@ -0,0 +1,233 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. + +package excelize + +import ( + "fmt" + "strings" +) + +// DataValidationType defined the type of data validation. +type DataValidationType int + +// Data validation types. +const ( + _DataValidationType = iota + typeNone // inline use + DataValidationTypeCustom + DataValidationTypeDate + DataValidationTypeDecimal + typeList // inline use + DataValidationTypeTextLeng + DataValidationTypeTime + // DataValidationTypeWhole Integer + DataValidationTypeWhole +) + +const ( + // dataValidationFormulaStrLen 255 characters+ 2 quotes + dataValidationFormulaStrLen = 257 + // dataValidationFormulaStrLenErr + dataValidationFormulaStrLenErr = "data validation must be 0-255 characters" +) + +// DataValidationErrorStyle defined the style of data validation error alert. +type DataValidationErrorStyle int + +// Data validation error styles. +const ( + _ DataValidationErrorStyle = iota + DataValidationErrorStyleStop + DataValidationErrorStyleWarning + DataValidationErrorStyleInformation +) + +// Data validation error styles. +const ( + styleStop = "stop" + styleWarning = "warning" + styleInformation = "information" +) + +// DataValidationOperator operator enum. +type DataValidationOperator int + +// Data validation operators. +const ( + _DataValidationOperator = iota + DataValidationOperatorBetween + DataValidationOperatorEqual + DataValidationOperatorGreaterThan + DataValidationOperatorGreaterThanOrEqual + DataValidationOperatorLessThan + DataValidationOperatorLessThanOrEqual + DataValidationOperatorNotBetween + DataValidationOperatorNotEqual +) + +// NewDataValidation return data validation struct. +func NewDataValidation(allowBlank bool) *DataValidation { + return &DataValidation{ + AllowBlank: allowBlank, + ShowErrorMessage: false, + ShowInputMessage: false, + } +} + +// SetError set error notice. +func (dd *DataValidation) SetError(style DataValidationErrorStyle, title, msg string) { + dd.Error = &msg + dd.ErrorTitle = &title + strStyle := styleStop + switch style { + case DataValidationErrorStyleStop: + strStyle = styleStop + case DataValidationErrorStyleWarning: + strStyle = styleWarning + case DataValidationErrorStyleInformation: + strStyle = styleInformation + + } + dd.ShowErrorMessage = true + dd.ErrorStyle = &strStyle +} + +// SetInput set prompt notice. +func (dd *DataValidation) SetInput(title, msg string) { + dd.ShowInputMessage = true + dd.PromptTitle = &title + dd.Prompt = &msg +} + +// SetDropList data validation list. +func (dd *DataValidation) SetDropList(keys []string) error { + dd.Formula1 = "\"" + strings.Join(keys, ",") + "\"" + dd.Type = convDataValidationType(typeList) + return nil +} + +// SetRange provides function to set data validation range in drop list. +func (dd *DataValidation) SetRange(f1, f2 int, t DataValidationType, o DataValidationOperator) error { + formula1 := fmt.Sprintf("%d", f1) + formula2 := fmt.Sprintf("%d", f2) + if dataValidationFormulaStrLen < len(dd.Formula1) || dataValidationFormulaStrLen < len(dd.Formula2) { + return fmt.Errorf(dataValidationFormulaStrLenErr) + } + + dd.Formula1 = formula1 + dd.Formula2 = formula2 + dd.Type = convDataValidationType(t) + dd.Operator = convDataValidationOperatior(o) + return nil +} + +// SetSqrefDropList provides set data validation on a range with source +// reference range of the worksheet by given data validation object and +// worksheet name. The data validation object can be created by +// NewDataValidation function. For example, set data validation on +// Sheet1!A7:B8 with validation criteria source Sheet1!E1:E3 settings, create +// in-cell dropdown by allowing list source: +// +// dvRange := excelize.NewDataValidation(true) +// dvRange.Sqref = "A7:B8" +// dvRange.SetSqrefDropList("E1:E3", true) +// xlsx.AddDataValidation("Sheet1", dvRange) +// +func (dd *DataValidation) SetSqrefDropList(sqref string, isCurrentSheet bool) error { + if isCurrentSheet { + dd.Formula1 = sqref + dd.Type = convDataValidationType(typeList) + return nil + } + return fmt.Errorf("cross-sheet sqref cell are not supported") +} + +// SetSqref provides function to set data validation range in drop list. +func (dd *DataValidation) SetSqref(sqref string) { + if dd.Sqref == "" { + dd.Sqref = sqref + } else { + dd.Sqref = fmt.Sprintf("%s %s", dd.Sqref, sqref) + } +} + +// convDataValidationType get excel data validation type. +func convDataValidationType(t DataValidationType) string { + typeMap := map[DataValidationType]string{ + typeNone: "none", + DataValidationTypeCustom: "custom", + DataValidationTypeDate: "date", + DataValidationTypeDecimal: "decimal", + typeList: "list", + DataValidationTypeTextLeng: "textLength", + DataValidationTypeTime: "time", + DataValidationTypeWhole: "whole", + } + + return typeMap[t] + +} + +// convDataValidationOperatior get excel data validation operator. +func convDataValidationOperatior(o DataValidationOperator) string { + typeMap := map[DataValidationOperator]string{ + DataValidationOperatorBetween: "between", + DataValidationOperatorEqual: "equal", + DataValidationOperatorGreaterThan: "greaterThan", + DataValidationOperatorGreaterThanOrEqual: "greaterThanOrEqual", + DataValidationOperatorLessThan: "lessThan", + DataValidationOperatorLessThanOrEqual: "lessThanOrEqual", + DataValidationOperatorNotBetween: "notBetween", + DataValidationOperatorNotEqual: "notEqual", + } + + return typeMap[o] + +} + +// AddDataValidation provides set data validation on a range of the worksheet +// by given data validation object and worksheet name. The data validation +// object can be created by NewDataValidation function. +// +// Example 1, set data validation on Sheet1!A1:B2 with validation criteria +// settings, show error alert after invalid data is entered with "Stop" style +// and custom title "error body": +// +// dvRange := excelize.NewDataValidation(true) +// dvRange.Sqref = "A1:B2" +// dvRange.SetRange(10, 20, excelize.DataValidationTypeWhole, excelize.DataValidationOperatorBetween) +// dvRange.SetError(excelize.DataValidationErrorStyleStop, "error title", "error body") +// xlsx.AddDataValidation("Sheet1", dvRange) +// +// Example 2, set data validation on Sheet1!A3:B4 with validation criteria +// settings, and show input message when cell is selected: +// +// dvRange = excelize.NewDataValidation(true) +// dvRange.Sqref = "A3:B4" +// dvRange.SetRange(10, 20, excelize.DataValidationTypeWhole, excelize.DataValidationOperatorGreaterThan) +// dvRange.SetInput("input title", "input body") +// xlsx.AddDataValidation("Sheet1", dvRange) +// +// Example 3, set data validation on Sheet1!A5:B6 with validation criteria +// settings, create in-cell dropdown by allowing list source: +// +// dvRange = excelize.NewDataValidation(true) +// dvRange.Sqref = "A5:B6" +// dvRange.SetDropList([]string{"1", "2", "3"}) +// xlsx.AddDataValidation("Sheet1", dvRange) +// +func (f *File) AddDataValidation(sheet string, dv *DataValidation) { + xlsx := f.workSheetReader(sheet) + if nil == xlsx.DataValidations { + xlsx.DataValidations = new(xlsxDataValidations) + } + xlsx.DataValidations.DataValidation = append(xlsx.DataValidations.DataValidation, dv) + xlsx.DataValidations.Count = len(xlsx.DataValidations.DataValidation) +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/date.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/date.go new file mode 100644 index 0000000000..7dc5ef811e --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/date.go @@ -0,0 +1,151 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. + +package excelize + +import ( + "math" + "time" +) + +// timeLocationUTC defined the UTC time location. +var timeLocationUTC, _ = time.LoadLocation("UTC") + +// timeToUTCTime provides a function to convert time to UTC time. +func timeToUTCTime(t time.Time) time.Time { + return time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), t.Nanosecond(), timeLocationUTC) +} + +// timeToExcelTime provides a function to convert time to Excel time. +func timeToExcelTime(t time.Time) float64 { + // TODO in future this should probably also handle date1904 and like TimeFromExcelTime + var excelTime float64 + var deltaDays int64 + excelTime = 0 + deltaDays = 290 * 364 + // check if UnixNano would be out of int64 range + for t.Unix() > deltaDays*24*60*60 { + // reduce by aprox. 290 years, which is max for int64 nanoseconds + delta := time.Duration(deltaDays) * 24 * time.Hour + excelTime = excelTime + float64(deltaDays) + t = t.Add(-delta) + } + // finally add remainder of UnixNano to keep nano precision + // and 25569 which is days between 1900 and 1970 + return excelTime + float64(t.UnixNano())/8.64e13 + 25569.0 +} + +// shiftJulianToNoon provides a function to process julian date to noon. +func shiftJulianToNoon(julianDays, julianFraction float64) (float64, float64) { + switch { + case -0.5 < julianFraction && julianFraction < 0.5: + julianFraction += 0.5 + case julianFraction >= 0.5: + julianDays++ + julianFraction -= 0.5 + case julianFraction <= -0.5: + julianDays-- + julianFraction += 1.5 + } + return julianDays, julianFraction +} + +// fractionOfADay provides a function to return the integer values for hour, +// minutes, seconds and nanoseconds that comprised a given fraction of a day. +// values would round to 1 us. +func fractionOfADay(fraction float64) (hours, minutes, seconds, nanoseconds int) { + + const ( + c1us = 1e3 + c1s = 1e9 + c1day = 24 * 60 * 60 * c1s + ) + + frac := int64(c1day*fraction + c1us/2) + nanoseconds = int((frac%c1s)/c1us) * c1us + frac /= c1s + seconds = int(frac % 60) + frac /= 60 + minutes = int(frac % 60) + hours = int(frac / 60) + return +} + +// julianDateToGregorianTime provides a function to convert julian date to +// gregorian time. +func julianDateToGregorianTime(part1, part2 float64) time.Time { + part1I, part1F := math.Modf(part1) + part2I, part2F := math.Modf(part2) + julianDays := part1I + part2I + julianFraction := part1F + part2F + julianDays, julianFraction = shiftJulianToNoon(julianDays, julianFraction) + day, month, year := doTheFliegelAndVanFlandernAlgorithm(int(julianDays)) + hours, minutes, seconds, nanoseconds := fractionOfADay(julianFraction) + return time.Date(year, time.Month(month), day, hours, minutes, seconds, nanoseconds, time.UTC) +} + +// doTheFliegelAndVanFlandernAlgorithm; By this point generations of +// programmers have repeated the algorithm sent to the editor of +// "Communications of the ACM" in 1968 (published in CACM, volume 11, number +// 10, October 1968, p.657). None of those programmers seems to have found it +// necessary to explain the constants or variable names set out by Henry F. +// Fliegel and Thomas C. Van Flandern. Maybe one day I'll buy that jounal and +// expand an explanation here - that day is not today. +func doTheFliegelAndVanFlandernAlgorithm(jd int) (day, month, year int) { + l := jd + 68569 + n := (4 * l) / 146097 + l = l - (146097*n+3)/4 + i := (4000 * (l + 1)) / 1461001 + l = l - (1461*i)/4 + 31 + j := (80 * l) / 2447 + d := l - (2447*j)/80 + l = j / 11 + m := j + 2 - (12 * l) + y := 100*(n-49) + i + l + return d, m, y +} + +// timeFromExcelTime provides a function to convert an excelTime +// representation (stored as a floating point number) to a time.Time. +func timeFromExcelTime(excelTime float64, date1904 bool) time.Time { + const MDD int64 = 106750 // Max time.Duration Days, aprox. 290 years + var date time.Time + var intPart = int64(excelTime) + // Excel uses Julian dates prior to March 1st 1900, and Gregorian + // thereafter. + if intPart <= 61 { + const OFFSET1900 = 15018.0 + const OFFSET1904 = 16480.0 + const MJD0 float64 = 2400000.5 + var date time.Time + if date1904 { + date = julianDateToGregorianTime(MJD0, excelTime+OFFSET1904) + } else { + date = julianDateToGregorianTime(MJD0, excelTime+OFFSET1900) + } + return date + } + var floatPart = excelTime - float64(intPart) + var dayNanoSeconds float64 = 24 * 60 * 60 * 1000 * 1000 * 1000 + if date1904 { + date = time.Date(1904, 1, 1, 0, 0, 0, 0, time.UTC) + } else { + date = time.Date(1899, 12, 30, 0, 0, 0, 0, time.UTC) + } + + // Duration is limited to aprox. 290 years + for intPart > MDD { + durationDays := time.Duration(MDD) * time.Hour * 24 + date = date.Add(durationDays) + intPart = intPart - MDD + } + durationDays := time.Duration(intPart) * time.Hour * 24 + durationPart := time.Duration(dayNanoSeconds * floatPart) + return date.Add(durationDays).Add(durationPart) +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/excelize.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/excelize.go new file mode 100644 index 0000000000..60480c8d84 --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/excelize.go @@ -0,0 +1,456 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. + +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. +// +// See https://xuri.me/excelize for more information about this package. +package excelize + +import ( + "archive/zip" + "bytes" + "encoding/xml" + "io" + "io/ioutil" + "os" + "strconv" + "strings" +) + +// File define a populated XLSX file struct. +type File struct { + checked map[string]bool + sheetMap map[string]string + ContentTypes *xlsxTypes + Path string + SharedStrings *xlsxSST + Sheet map[string]*xlsxWorksheet + SheetCount int + Styles *xlsxStyleSheet + Theme *xlsxTheme + WorkBook *xlsxWorkbook + WorkBookRels *xlsxWorkbookRels + XLSX map[string][]byte +} + +// OpenFile take the name of an XLSX file and returns a populated XLSX file +// struct for it. +func OpenFile(filename string) (*File, error) { + file, err := os.Open(filename) + if err != nil { + return nil, err + } + defer file.Close() + f, err := OpenReader(file) + if err != nil { + return nil, err + } + f.Path = filename + return f, nil +} + +// OpenReader take an io.Reader and return a populated XLSX file. +func OpenReader(r io.Reader) (*File, error) { + b, err := ioutil.ReadAll(r) + if err != nil { + return nil, err + } + + zr, err := zip.NewReader(bytes.NewReader(b), int64(len(b))) + if err != nil { + return nil, err + } + + file, sheetCount, err := ReadZipReader(zr) + if err != nil { + return nil, err + } + f := &File{ + checked: make(map[string]bool), + Sheet: make(map[string]*xlsxWorksheet), + SheetCount: sheetCount, + XLSX: file, + } + f.sheetMap = f.getSheetMap() + f.Styles = f.stylesReader() + f.Theme = f.themeReader() + return f, nil +} + +// setDefaultTimeStyle provides a function to set default numbers format for +// time.Time type cell value by given worksheet name, cell coordinates and +// number format code. +func (f *File) setDefaultTimeStyle(sheet, axis string, format int) { + if f.GetCellStyle(sheet, axis) == 0 { + style, _ := f.NewStyle(`{"number_format": ` + strconv.Itoa(format) + `}`) + f.SetCellStyle(sheet, axis, axis, style) + } +} + +// workSheetReader provides a function to get the pointer to the structure +// after deserialization by given worksheet name. +func (f *File) workSheetReader(sheet string) *xlsxWorksheet { + name, ok := f.sheetMap[trimSheetName(sheet)] + if !ok { + name = "xl/worksheets/" + strings.ToLower(sheet) + ".xml" + } + if f.Sheet[name] == nil { + var xlsx xlsxWorksheet + _ = xml.Unmarshal(namespaceStrictToTransitional(f.readXML(name)), &xlsx) + if f.checked == nil { + f.checked = make(map[string]bool) + } + ok := f.checked[name] + if !ok { + checkSheet(&xlsx) + checkRow(&xlsx) + f.checked[name] = true + } + f.Sheet[name] = &xlsx + } + return f.Sheet[name] +} + +// checkSheet provides a function to fill each row element and make that is +// continuous in a worksheet of XML. +func checkSheet(xlsx *xlsxWorksheet) { + row := len(xlsx.SheetData.Row) + if row >= 1 { + lastRow := xlsx.SheetData.Row[row-1].R + if lastRow >= row { + row = lastRow + } + } + sheetData := xlsxSheetData{} + existsRows := map[int]int{} + for k := range xlsx.SheetData.Row { + existsRows[xlsx.SheetData.Row[k].R] = k + } + for i := 0; i < row; i++ { + _, ok := existsRows[i+1] + if ok { + sheetData.Row = append(sheetData.Row, xlsx.SheetData.Row[existsRows[i+1]]) + } else { + sheetData.Row = append(sheetData.Row, xlsxRow{ + R: i + 1, + }) + } + } + xlsx.SheetData = sheetData +} + +// replaceWorkSheetsRelationshipsNameSpaceBytes provides a function to replace +// xl/worksheets/sheet%d.xml XML tags to self-closing for compatible Microsoft +// Office Excel 2007. +func replaceWorkSheetsRelationshipsNameSpaceBytes(workbookMarshal []byte) []byte { + var oldXmlns = []byte(``) + var newXmlns = []byte(``) + workbookMarshal = bytes.Replace(workbookMarshal, oldXmlns, newXmlns, -1) + return workbookMarshal +} + +// UpdateLinkedValue fix linked values within a spreadsheet are not updating in +// Office Excel 2007 and 2010. This function will be remove value tag when met a +// cell have a linked value. Reference +// https://social.technet.microsoft.com/Forums/office/en-US/e16bae1f-6a2c-4325-8013-e989a3479066/excel-2010-linked-cells-not-updating?forum=excel +// +// Notice: after open XLSX file Excel will be update linked value and generate +// new value and will prompt save file or not. +// +// For example: +// +// +// +// SUM(Sheet2!D2,Sheet2!D11) +// 100 +// +// +// +// to +// +// +// +// SUM(Sheet2!D2,Sheet2!D11) +// +// +// +func (f *File) UpdateLinkedValue() { + for _, name := range f.GetSheetMap() { + xlsx := f.workSheetReader(name) + for indexR := range xlsx.SheetData.Row { + for indexC, col := range xlsx.SheetData.Row[indexR].C { + if col.F != nil && col.V != "" { + xlsx.SheetData.Row[indexR].C[indexC].V = "" + xlsx.SheetData.Row[indexR].C[indexC].T = "" + } + } + } + } +} + +// adjustHelper provides a function to adjust rows and columns dimensions, +// hyperlinks, merged cells and auto filter when inserting or deleting rows or +// columns. +// +// sheet: Worksheet name that we're editing +// column: Index number of the column we're inserting/deleting before +// row: Index number of the row we're inserting/deleting before +// offset: Number of rows/column to insert/delete negative values indicate deletion +// +// TODO: adjustPageBreaks, adjustComments, adjustDataValidations, adjustProtectedCells +// +func (f *File) adjustHelper(sheet string, column, row, offset int) { + xlsx := f.workSheetReader(sheet) + f.adjustRowDimensions(xlsx, row, offset) + f.adjustColDimensions(xlsx, column, offset) + f.adjustHyperlinks(sheet, column, row, offset) + f.adjustMergeCells(xlsx, column, row, offset) + f.adjustAutoFilter(xlsx, column, row, offset) + checkSheet(xlsx) + checkRow(xlsx) +} + +// adjustColDimensions provides a function to update column dimensions when +// inserting or deleting rows or columns. +func (f *File) adjustColDimensions(xlsx *xlsxWorksheet, column, offset int) { + for i, r := range xlsx.SheetData.Row { + for k, v := range r.C { + axis := v.R + col := string(strings.Map(letterOnlyMapF, axis)) + row, _ := strconv.Atoi(strings.Map(intOnlyMapF, axis)) + yAxis := TitleToNumber(col) + if yAxis >= column && column != -1 { + xlsx.SheetData.Row[i].C[k].R = ToAlphaString(yAxis+offset) + strconv.Itoa(row) + } + } + } +} + +// adjustRowDimensions provides a function to update row dimensions when +// inserting or deleting rows or columns. +func (f *File) adjustRowDimensions(xlsx *xlsxWorksheet, rowIndex, offset int) { + if rowIndex == -1 { + return + } + for i, r := range xlsx.SheetData.Row { + if r.R >= rowIndex { + f.ajustSingleRowDimensions(&xlsx.SheetData.Row[i], offset) + } + } +} + +// ajustSingleRowDimensions provides a function to ajust single row +// dimensions. +func (f *File) ajustSingleRowDimensions(r *xlsxRow, offset int) { + r.R += offset + for i, col := range r.C { + row, _ := strconv.Atoi(strings.Map(intOnlyMapF, col.R)) + r.C[i].R = string(strings.Map(letterOnlyMapF, col.R)) + strconv.Itoa(row+offset) + } +} + +// adjustHyperlinks provides a function to update hyperlinks when inserting or +// deleting rows or columns. +func (f *File) adjustHyperlinks(sheet string, column, rowIndex, offset int) { + xlsx := f.workSheetReader(sheet) + + // order is important + if xlsx.Hyperlinks != nil && offset < 0 { + for i, v := range xlsx.Hyperlinks.Hyperlink { + axis := v.Ref + col := string(strings.Map(letterOnlyMapF, axis)) + row, _ := strconv.Atoi(strings.Map(intOnlyMapF, axis)) + yAxis := TitleToNumber(col) + if row == rowIndex || yAxis == column { + f.deleteSheetRelationships(sheet, v.RID) + if len(xlsx.Hyperlinks.Hyperlink) > 1 { + xlsx.Hyperlinks.Hyperlink = append(xlsx.Hyperlinks.Hyperlink[:i], xlsx.Hyperlinks.Hyperlink[i+1:]...) + } else { + xlsx.Hyperlinks = nil + } + } + } + } + + if xlsx.Hyperlinks != nil { + for i, v := range xlsx.Hyperlinks.Hyperlink { + axis := v.Ref + col := string(strings.Map(letterOnlyMapF, axis)) + row, _ := strconv.Atoi(strings.Map(intOnlyMapF, axis)) + xAxis := row + offset + yAxis := TitleToNumber(col) + if rowIndex != -1 && row >= rowIndex { + xlsx.Hyperlinks.Hyperlink[i].Ref = col + strconv.Itoa(xAxis) + } + if column != -1 && yAxis >= column { + xlsx.Hyperlinks.Hyperlink[i].Ref = ToAlphaString(yAxis+offset) + strconv.Itoa(row) + } + } + } +} + +// adjustMergeCellsHelper provides a function to update merged cells when +// inserting or deleting rows or columns. +func (f *File) adjustMergeCellsHelper(xlsx *xlsxWorksheet, column, rowIndex, offset int) { + if xlsx.MergeCells != nil { + for k, v := range xlsx.MergeCells.Cells { + beg := strings.Split(v.Ref, ":")[0] + end := strings.Split(v.Ref, ":")[1] + + begcol := string(strings.Map(letterOnlyMapF, beg)) + begrow, _ := strconv.Atoi(strings.Map(intOnlyMapF, beg)) + begxAxis := begrow + offset + begyAxis := TitleToNumber(begcol) + + endcol := string(strings.Map(letterOnlyMapF, end)) + endrow, _ := strconv.Atoi(strings.Map(intOnlyMapF, end)) + endxAxis := endrow + offset + endyAxis := TitleToNumber(endcol) + + if rowIndex != -1 { + if begrow > 1 && begrow >= rowIndex { + beg = begcol + strconv.Itoa(begxAxis) + } + if endrow > 1 && endrow >= rowIndex { + end = endcol + strconv.Itoa(endxAxis) + } + } + + if column != -1 { + if begyAxis >= column { + beg = ToAlphaString(begyAxis+offset) + strconv.Itoa(endrow) + } + if endyAxis >= column { + end = ToAlphaString(endyAxis+offset) + strconv.Itoa(endrow) + } + } + + xlsx.MergeCells.Cells[k].Ref = beg + ":" + end + } + } +} + +// adjustMergeCells provides a function to update merged cells when inserting +// or deleting rows or columns. +func (f *File) adjustMergeCells(xlsx *xlsxWorksheet, column, rowIndex, offset int) { + f.adjustMergeCellsHelper(xlsx, column, rowIndex, offset) + + if xlsx.MergeCells != nil && offset < 0 { + for k, v := range xlsx.MergeCells.Cells { + beg := strings.Split(v.Ref, ":")[0] + end := strings.Split(v.Ref, ":")[1] + if beg == end { + xlsx.MergeCells.Count += offset + if len(xlsx.MergeCells.Cells) > 1 { + xlsx.MergeCells.Cells = append(xlsx.MergeCells.Cells[:k], xlsx.MergeCells.Cells[k+1:]...) + } else { + xlsx.MergeCells = nil + } + } + } + } +} + +// adjustAutoFilter provides a function to update the auto filter when +// inserting or deleting rows or columns. +func (f *File) adjustAutoFilter(xlsx *xlsxWorksheet, column, rowIndex, offset int) { + f.adjustAutoFilterHelper(xlsx, column, rowIndex, offset) + + if xlsx.AutoFilter != nil { + beg := strings.Split(xlsx.AutoFilter.Ref, ":")[0] + end := strings.Split(xlsx.AutoFilter.Ref, ":")[1] + + begcol := string(strings.Map(letterOnlyMapF, beg)) + begrow, _ := strconv.Atoi(strings.Map(intOnlyMapF, beg)) + begxAxis := begrow + offset + + endcol := string(strings.Map(letterOnlyMapF, end)) + endrow, _ := strconv.Atoi(strings.Map(intOnlyMapF, end)) + endxAxis := endrow + offset + endyAxis := TitleToNumber(endcol) + + if rowIndex != -1 { + if begrow >= rowIndex { + beg = begcol + strconv.Itoa(begxAxis) + } + if endrow >= rowIndex { + end = endcol + strconv.Itoa(endxAxis) + } + } + + if column != -1 && endyAxis >= column { + end = ToAlphaString(endyAxis+offset) + strconv.Itoa(endrow) + } + xlsx.AutoFilter.Ref = beg + ":" + end + } +} + +// adjustAutoFilterHelper provides a function to update the auto filter when +// inserting or deleting rows or columns. +func (f *File) adjustAutoFilterHelper(xlsx *xlsxWorksheet, column, rowIndex, offset int) { + if xlsx.AutoFilter != nil { + beg := strings.Split(xlsx.AutoFilter.Ref, ":")[0] + end := strings.Split(xlsx.AutoFilter.Ref, ":")[1] + + begcol := string(strings.Map(letterOnlyMapF, beg)) + begrow, _ := strconv.Atoi(strings.Map(intOnlyMapF, beg)) + begyAxis := TitleToNumber(begcol) + + endcol := string(strings.Map(letterOnlyMapF, end)) + endyAxis := TitleToNumber(endcol) + endrow, _ := strconv.Atoi(strings.Map(intOnlyMapF, end)) + + if (begrow == rowIndex && offset < 0) || (column == begyAxis && column == endyAxis) { + xlsx.AutoFilter = nil + for i, r := range xlsx.SheetData.Row { + if begrow < r.R && r.R <= endrow { + xlsx.SheetData.Row[i].Hidden = false + } + } + } + } +} + +// GetMergeCells provides a function to get all merged cells from a worksheet currently. +func (f *File) GetMergeCells(sheet string) []MergeCell { + mergeCells := []MergeCell{} + + xlsx := f.workSheetReader(sheet) + if xlsx.MergeCells != nil { + for i := 0; i < len(xlsx.MergeCells.Cells); i++ { + ref := xlsx.MergeCells.Cells[i].Ref + axis := strings.Split(ref, ":")[0] + mergeCells = append(mergeCells, []string{ref, f.GetCellValue(sheet, axis)}) + } + } + + return mergeCells +} + +// MergeCell define a merged cell data. +// It consists of the following structure. +// example: []string{"D4:E10", "cell value"} +type MergeCell []string + +// GetCellValue returns merged cell value. +func (m *MergeCell) GetCellValue() string { + return (*m)[1] +} + +// GetStartAxis returns the merge start axis. +// example: "C2" +func (m *MergeCell) GetStartAxis() string { + axis := strings.Split((*m)[0], ":") + return axis[0] +} + +// GetEndAxis returns the merge end axis. +// example: "D4" +func (m *MergeCell) GetEndAxis() string { + axis := strings.Split((*m)[0], ":") + return axis[1] +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/excelize.png b/vendor/github.com/360EntSecGroup-Skylar/excelize/excelize.png new file mode 100644 index 0000000000..5d0766ba13 Binary files /dev/null and b/vendor/github.com/360EntSecGroup-Skylar/excelize/excelize.png differ diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/file.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/file.go new file mode 100644 index 0000000000..3e49803306 --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/file.go @@ -0,0 +1,106 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. + +package excelize + +import ( + "archive/zip" + "bytes" + "fmt" + "io" + "os" +) + +// NewFile provides a function to create new file by default template. For +// example: +// +// xlsx := NewFile() +// +func NewFile() *File { + file := make(map[string][]byte) + file["_rels/.rels"] = []byte(XMLHeader + templateRels) + file["docProps/app.xml"] = []byte(XMLHeader + templateDocpropsApp) + file["docProps/core.xml"] = []byte(XMLHeader + templateDocpropsCore) + file["xl/_rels/workbook.xml.rels"] = []byte(XMLHeader + templateWorkbookRels) + file["xl/theme/theme1.xml"] = []byte(XMLHeader + templateTheme) + file["xl/worksheets/sheet1.xml"] = []byte(XMLHeader + templateSheet) + file["xl/styles.xml"] = []byte(XMLHeader + templateStyles) + file["xl/workbook.xml"] = []byte(XMLHeader + templateWorkbook) + file["[Content_Types].xml"] = []byte(XMLHeader + templateContentTypes) + f := &File{ + sheetMap: make(map[string]string), + Sheet: make(map[string]*xlsxWorksheet), + SheetCount: 1, + XLSX: file, + } + f.ContentTypes = f.contentTypesReader() + f.Styles = f.stylesReader() + f.WorkBook = f.workbookReader() + f.WorkBookRels = f.workbookRelsReader() + f.Sheet["xl/worksheets/sheet1.xml"] = f.workSheetReader("Sheet1") + f.sheetMap["Sheet1"] = "xl/worksheets/sheet1.xml" + f.Theme = f.themeReader() + return f +} + +// Save provides a function to override the xlsx file with origin path. +func (f *File) Save() error { + if f.Path == "" { + return fmt.Errorf("no path defined for file, consider File.WriteTo or File.Write") + } + return f.SaveAs(f.Path) +} + +// SaveAs provides a function to create or update to an xlsx file at the +// provided path. +func (f *File) SaveAs(name string) error { + file, err := os.OpenFile(name, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0666) + if err != nil { + return err + } + defer file.Close() + return f.Write(file) +} + +// Write provides a function to write to an io.Writer. +func (f *File) Write(w io.Writer) error { + _, err := f.WriteTo(w) + return err +} + +// WriteTo implements io.WriterTo to write the file. +func (f *File) WriteTo(w io.Writer) (int64, error) { + buf, err := f.WriteToBuffer() + if err != nil { + return 0, err + } + return buf.WriteTo(w) +} + +// WriteToBuffer provides a function to get bytes.Buffer from the saved file. +func (f *File) WriteToBuffer() (*bytes.Buffer, error) { + buf := new(bytes.Buffer) + zw := zip.NewWriter(buf) + f.contentTypesWriter() + f.workbookWriter() + f.workbookRelsWriter() + f.worksheetWriter() + f.styleSheetWriter() + for path, content := range f.XLSX { + fi, err := zw.Create(path) + if err != nil { + return buf, err + } + _, err = fi.Write(content) + if err != nil { + return buf, err + } + } + return buf, zw.Close() +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/hsl.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/hsl.go new file mode 100644 index 0000000000..c30c165a5b --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/hsl.go @@ -0,0 +1,139 @@ +// Copyright (c) 2012 Rodrigo Moraes. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package excelize + +import ( + "image/color" + "math" +) + +// HSLModel converts any color.Color to a HSL color. +var HSLModel = color.ModelFunc(hslModel) + +// HSL represents a cylindrical coordinate of points in an RGB color model. +// +// Values are in the range 0 to 1. +type HSL struct { + H, S, L float64 +} + +// RGBA returns the alpha-premultiplied red, green, blue and alpha values +// for the HSL. +func (c HSL) RGBA() (uint32, uint32, uint32, uint32) { + r, g, b := HSLToRGB(c.H, c.S, c.L) + return uint32(r) * 0x101, uint32(g) * 0x101, uint32(b) * 0x101, 0xffff +} + +// hslModel converts a color.Color to HSL. +func hslModel(c color.Color) color.Color { + if _, ok := c.(HSL); ok { + return c + } + r, g, b, _ := c.RGBA() + h, s, l := RGBToHSL(uint8(r>>8), uint8(g>>8), uint8(b>>8)) + return HSL{h, s, l} +} + +// RGBToHSL converts an RGB triple to a HSL triple. +func RGBToHSL(r, g, b uint8) (h, s, l float64) { + fR := float64(r) / 255 + fG := float64(g) / 255 + fB := float64(b) / 255 + max := math.Max(math.Max(fR, fG), fB) + min := math.Min(math.Min(fR, fG), fB) + l = (max + min) / 2 + if max == min { + // Achromatic. + h, s = 0, 0 + } else { + // Chromatic. + d := max - min + if l > 0.5 { + s = d / (2.0 - max - min) + } else { + s = d / (max + min) + } + switch max { + case fR: + h = (fG - fB) / d + if fG < fB { + h += 6 + } + case fG: + h = (fB-fR)/d + 2 + case fB: + h = (fR-fG)/d + 4 + } + h /= 6 + } + return +} + +// HSLToRGB converts an HSL triple to a RGB triple. +func HSLToRGB(h, s, l float64) (r, g, b uint8) { + var fR, fG, fB float64 + if s == 0 { + fR, fG, fB = l, l, l + } else { + var q float64 + if l < 0.5 { + q = l * (1 + s) + } else { + q = l + s - s*l + } + p := 2*l - q + fR = hueToRGB(p, q, h+1.0/3) + fG = hueToRGB(p, q, h) + fB = hueToRGB(p, q, h-1.0/3) + } + r = uint8((fR * 255) + 0.5) + g = uint8((fG * 255) + 0.5) + b = uint8((fB * 255) + 0.5) + return +} + +// hueToRGB is a helper function for HSLToRGB. +func hueToRGB(p, q, t float64) float64 { + if t < 0 { + t++ + } + if t > 1 { + t-- + } + if t < 1.0/6 { + return p + (q-p)*6*t + } + if t < 0.5 { + return q + } + if t < 2.0/3 { + return p + (q-p)*(2.0/3-t)*6 + } + return p +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/lib.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/lib.go new file mode 100644 index 0000000000..99c513edbf --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/lib.go @@ -0,0 +1,229 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. + +package excelize + +import ( + "archive/zip" + "bytes" + "io" + "log" + "math" + "strconv" + "strings" + "unicode" +) + +// ReadZipReader can be used to read an XLSX in memory without touching the +// filesystem. +func ReadZipReader(r *zip.Reader) (map[string][]byte, int, error) { + fileList := make(map[string][]byte) + worksheets := 0 + for _, v := range r.File { + fileList[v.Name] = readFile(v) + if len(v.Name) > 18 { + if v.Name[0:19] == "xl/worksheets/sheet" { + worksheets++ + } + } + } + return fileList, worksheets, nil +} + +// readXML provides a function to read XML content as string. +func (f *File) readXML(name string) []byte { + if content, ok := f.XLSX[name]; ok { + return content + } + return []byte{} +} + +// saveFileList provides a function to update given file content in file list +// of XLSX. +func (f *File) saveFileList(name string, content []byte) { + newContent := make([]byte, 0, len(XMLHeader)+len(content)) + newContent = append(newContent, []byte(XMLHeader)...) + newContent = append(newContent, content...) + f.XLSX[name] = newContent +} + +// Read file content as string in a archive file. +func readFile(file *zip.File) []byte { + rc, err := file.Open() + if err != nil { + log.Fatal(err) + } + buff := bytes.NewBuffer(nil) + _, _ = io.Copy(buff, rc) + rc.Close() + return buff.Bytes() +} + +// ToAlphaString provides a function to convert integer to Excel sheet column +// title. For example convert 36 to column title AK: +// +// excelize.ToAlphaString(36) +// +func ToAlphaString(value int) string { + if value < 0 { + return "" + } + var ans string + i := value + 1 + for i > 0 { + ans = string((i-1)%26+65) + ans + i = (i - 1) / 26 + } + return ans +} + +// TitleToNumber provides a function to convert Excel sheet column title to +// int (this function doesn't do value check currently). For example convert +// AK and ak to column title 36: +// +// excelize.TitleToNumber("AK") +// excelize.TitleToNumber("ak") +// +func TitleToNumber(s string) int { + weight := 0.0 + sum := 0 + for i := len(s) - 1; i >= 0; i-- { + ch := int(s[i]) + if int(s[i]) >= int('a') && int(s[i]) <= int('z') { + ch = int(s[i]) - 32 + } + sum = sum + (ch-int('A')+1)*int(math.Pow(26, weight)) + weight++ + } + return sum - 1 +} + +// letterOnlyMapF is used in conjunction with strings.Map to return only the +// characters A-Z and a-z in a string. +func letterOnlyMapF(rune rune) rune { + switch { + case 'A' <= rune && rune <= 'Z': + return rune + case 'a' <= rune && rune <= 'z': + return rune - 32 + } + return -1 +} + +// intOnlyMapF is used in conjunction with strings.Map to return only the +// numeric portions of a string. +func intOnlyMapF(rune rune) rune { + if rune >= 48 && rune < 58 { + return rune + } + return -1 +} + +// boolPtr returns a pointer to a bool with the given value. +func boolPtr(b bool) *bool { return &b } + +// defaultTrue returns true if b is nil, or the pointed value. +func defaultTrue(b *bool) bool { + if b == nil { + return true + } + return *b +} + +// axisLowerOrEqualThan returns true if axis1 <= axis2 axis1/axis2 can be +// either a column or a row axis, e.g. "A", "AAE", "42", "1", etc. +// +// For instance, the following comparisons are all true: +// +// "A" <= "B" +// "A" <= "AA" +// "B" <= "AA" +// "BC" <= "ABCD" (in a XLSX sheet, the BC col comes before the ABCD col) +// "1" <= "2" +// "2" <= "11" (in a XLSX sheet, the row 2 comes before the row 11) +// and so on +func axisLowerOrEqualThan(axis1, axis2 string) bool { + if len(axis1) < len(axis2) { + return true + } else if len(axis1) > len(axis2) { + return false + } else { + return axis1 <= axis2 + } +} + +// getCellColRow returns the two parts of a cell identifier (its col and row) +// as strings +// +// For instance: +// +// "C220" => "C", "220" +// "aaef42" => "aaef", "42" +// "" => "", "" +func getCellColRow(cell string) (col, row string) { + for index, rune := range cell { + if unicode.IsDigit(rune) { + return cell[:index], cell[index:] + } + + } + + return cell, "" +} + +// parseFormatSet provides a method to convert format string to []byte and +// handle empty string. +func parseFormatSet(formatSet string) []byte { + if formatSet != "" { + return []byte(formatSet) + } + return []byte("{}") +} + +// namespaceStrictToTransitional provides a method to convert Strict and +// Transitional namespaces. +func namespaceStrictToTransitional(content []byte) []byte { + var namespaceTranslationDic = map[string]string{ + StrictSourceRelationship: SourceRelationship, + StrictSourceRelationshipChart: SourceRelationshipChart, + StrictSourceRelationshipComments: SourceRelationshipComments, + StrictSourceRelationshipImage: SourceRelationshipImage, + StrictNameSpaceSpreadSheet: NameSpaceSpreadSheet, + } + for s, n := range namespaceTranslationDic { + content = bytes.Replace(content, []byte(s), []byte(n), -1) + } + return content +} + +// genSheetPasswd provides a method to generate password for worksheet +// protection by given plaintext. When an Excel sheet is being protected with +// a password, a 16-bit (two byte) long hash is generated. To verify a +// password, it is compared to the hash. Obviously, if the input data volume +// is great, numerous passwords will match the same hash. Here is the +// algorithm to create the hash value: +// +// take the ASCII values of all characters shift left the first character 1 bit, the second 2 bits and so on (use only the lower 15 bits and rotate all higher bits, the highest bit of the 16-bit value is always 0 [signed short]) +// XOR all these values +// XOR the count of characters +// XOR the constant 0xCE4B +func genSheetPasswd(plaintext string) string { + var password int64 = 0x0000 + var charPos uint = 1 + for _, v := range plaintext { + value := int64(v) << charPos + charPos++ + rotatedBits := value >> 15 // rotated bits beyond bit 15 + value &= 0x7fff // first 15 bits + password ^= (value | rotatedBits) + } + password ^= int64(len(plaintext)) + password ^= 0xCE4B + return strings.ToUpper(strconv.FormatInt(password, 16)) +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/logo.png b/vendor/github.com/360EntSecGroup-Skylar/excelize/logo.png new file mode 100644 index 0000000000..32235b8aeb Binary files /dev/null and b/vendor/github.com/360EntSecGroup-Skylar/excelize/logo.png differ diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/picture.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/picture.go new file mode 100644 index 0000000000..763d89a6c7 --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/picture.go @@ -0,0 +1,533 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. + +package excelize + +import ( + "bytes" + "encoding/json" + "encoding/xml" + "errors" + "image" + "io/ioutil" + "os" + "path" + "path/filepath" + "strconv" + "strings" +) + +// parseFormatPictureSet provides a function to parse the format settings of +// the picture with default value. +func parseFormatPictureSet(formatSet string) (*formatPicture, error) { + format := formatPicture{ + FPrintsWithSheet: true, + FLocksWithSheet: false, + NoChangeAspect: false, + OffsetX: 0, + OffsetY: 0, + XScale: 1.0, + YScale: 1.0, + } + err := json.Unmarshal(parseFormatSet(formatSet), &format) + return &format, err +} + +// AddPicture provides the method to add picture in a sheet by given picture +// format set (such as offset, scale, aspect ratio setting and print settings) +// and file path. For example: +// +// package main +// +// import ( +// "fmt" +// _ "image/gif" +// _ "image/jpeg" +// _ "image/png" +// +// "github.com/360EntSecGroup-Skylar/excelize" +// ) +// +// func main() { +// xlsx := excelize.NewFile() +// // Insert a picture. +// err := xlsx.AddPicture("Sheet1", "A2", "./image1.jpg", "") +// if err != nil { +// fmt.Println(err) +// } +// // Insert a picture scaling in the cell with location hyperlink. +// err = xlsx.AddPicture("Sheet1", "D2", "./image1.png", `{"x_scale": 0.5, "y_scale": 0.5, "hyperlink": "#Sheet2!D8", "hyperlink_type": "Location"}`) +// if err != nil { +// fmt.Println(err) +// } +// // Insert a picture offset in the cell with external hyperlink, printing and positioning support. +// err = xlsx.AddPicture("Sheet1", "H2", "./image3.gif", `{"x_offset": 15, "y_offset": 10, "hyperlink": "https://github.com/360EntSecGroup-Skylar/excelize", "hyperlink_type": "External", "print_obj": true, "lock_aspect_ratio": false, "locked": false, "positioning": "oneCell"}`) +// if err != nil { +// fmt.Println(err) +// } +// err = xlsx.SaveAs("./Book1.xlsx") +// if err != nil { +// fmt.Println(err) +// } +// } +// +// LinkType defines two types of hyperlink "External" for web site or +// "Location" for moving to one of cell in this workbook. When the +// "hyperlink_type" is "Location", coordinates need to start with "#". +// +// Positioning defines two types of the position of a picture in an Excel +// spreadsheet, "oneCell" (Move but don't size with cells) or "absolute" +// (Don't move or size with cells). If you don't set this parameter, default +// positioning is move and size with cells. +func (f *File) AddPicture(sheet, cell, picture, format string) error { + var err error + // Check picture exists first. + if _, err = os.Stat(picture); os.IsNotExist(err) { + return err + } + ext, ok := supportImageTypes[path.Ext(picture)] + if !ok { + return errors.New("unsupported image extension") + } + file, _ := ioutil.ReadFile(picture) + _, name := filepath.Split(picture) + return f.AddPictureFromBytes(sheet, cell, format, name, ext, file) +} + +// AddPictureFromBytes provides the method to add picture in a sheet by given +// picture format set (such as offset, scale, aspect ratio setting and print +// settings), file base name, extension name and file bytes. For example: +// +// package main +// +// import ( +// "fmt" +// _ "image/jpeg" +// "io/ioutil" +// +// "github.com/360EntSecGroup-Skylar/excelize" +// ) +// +// func main() { +// xlsx := excelize.NewFile() +// +// file, err := ioutil.ReadFile("./image1.jpg") +// if err != nil { +// fmt.Println(err) +// } +// err = xlsx.AddPictureFromBytes("Sheet1", "A2", "", "Excel Logo", ".jpg", file) +// if err != nil { +// fmt.Println(err) +// } +// err = xlsx.SaveAs("./Book1.xlsx") +// if err != nil { +// fmt.Println(err) +// } +// } +// +func (f *File) AddPictureFromBytes(sheet, cell, format, name, extension string, file []byte) error { + var err error + var drawingHyperlinkRID int + var hyperlinkType string + ext, ok := supportImageTypes[extension] + if !ok { + return errors.New("unsupported image extension") + } + formatSet, err := parseFormatPictureSet(format) + if err != nil { + return err + } + image, _, err := image.DecodeConfig(bytes.NewReader(file)) + if err != nil { + return err + } + // Read sheet data. + xlsx := f.workSheetReader(sheet) + // Add first picture for given sheet, create xl/drawings/ and xl/drawings/_rels/ folder. + drawingID := f.countDrawings() + 1 + pictureID := f.countMedia() + 1 + drawingXML := "xl/drawings/drawing" + strconv.Itoa(drawingID) + ".xml" + drawingID, drawingXML = f.prepareDrawing(xlsx, drawingID, sheet, drawingXML) + drawingRID := f.addDrawingRelationships(drawingID, SourceRelationshipImage, "../media/image"+strconv.Itoa(pictureID)+ext, hyperlinkType) + // Add picture with hyperlink. + if formatSet.Hyperlink != "" && formatSet.HyperlinkType != "" { + if formatSet.HyperlinkType == "External" { + hyperlinkType = formatSet.HyperlinkType + } + drawingHyperlinkRID = f.addDrawingRelationships(drawingID, SourceRelationshipHyperLink, formatSet.Hyperlink, hyperlinkType) + } + f.addDrawingPicture(sheet, drawingXML, cell, name, image.Width, image.Height, drawingRID, drawingHyperlinkRID, formatSet) + f.addMedia(file, ext) + f.addContentTypePart(drawingID, "drawings") + return err +} + +// addSheetRelationships provides a function to add +// xl/worksheets/_rels/sheet%d.xml.rels by given worksheet name, relationship +// type and target. +func (f *File) addSheetRelationships(sheet, relType, target, targetMode string) int { + name, ok := f.sheetMap[trimSheetName(sheet)] + if !ok { + name = strings.ToLower(sheet) + ".xml" + } + var rels = "xl/worksheets/_rels/" + strings.TrimPrefix(name, "xl/worksheets/") + ".rels" + var sheetRels xlsxWorkbookRels + var rID = 1 + var ID bytes.Buffer + ID.WriteString("rId") + ID.WriteString(strconv.Itoa(rID)) + _, ok = f.XLSX[rels] + if ok { + ID.Reset() + _ = xml.Unmarshal(namespaceStrictToTransitional(f.readXML(rels)), &sheetRels) + rID = len(sheetRels.Relationships) + 1 + ID.WriteString("rId") + ID.WriteString(strconv.Itoa(rID)) + } + sheetRels.Relationships = append(sheetRels.Relationships, xlsxWorkbookRelation{ + ID: ID.String(), + Type: relType, + Target: target, + TargetMode: targetMode, + }) + output, _ := xml.Marshal(sheetRels) + f.saveFileList(rels, output) + return rID +} + +// deleteSheetRelationships provides a function to delete relationships in +// xl/worksheets/_rels/sheet%d.xml.rels by given worksheet name and +// relationship index. +func (f *File) deleteSheetRelationships(sheet, rID string) { + name, ok := f.sheetMap[trimSheetName(sheet)] + if !ok { + name = strings.ToLower(sheet) + ".xml" + } + var rels = "xl/worksheets/_rels/" + strings.TrimPrefix(name, "xl/worksheets/") + ".rels" + var sheetRels xlsxWorkbookRels + _ = xml.Unmarshal(namespaceStrictToTransitional(f.readXML(rels)), &sheetRels) + for k, v := range sheetRels.Relationships { + if v.ID == rID { + sheetRels.Relationships = append(sheetRels.Relationships[:k], sheetRels.Relationships[k+1:]...) + } + } + output, _ := xml.Marshal(sheetRels) + f.saveFileList(rels, output) +} + +// addSheetLegacyDrawing provides a function to add legacy drawing element to +// xl/worksheets/sheet%d.xml by given worksheet name and relationship index. +func (f *File) addSheetLegacyDrawing(sheet string, rID int) { + xlsx := f.workSheetReader(sheet) + xlsx.LegacyDrawing = &xlsxLegacyDrawing{ + RID: "rId" + strconv.Itoa(rID), + } +} + +// addSheetDrawing provides a function to add drawing element to +// xl/worksheets/sheet%d.xml by given worksheet name and relationship index. +func (f *File) addSheetDrawing(sheet string, rID int) { + xlsx := f.workSheetReader(sheet) + xlsx.Drawing = &xlsxDrawing{ + RID: "rId" + strconv.Itoa(rID), + } +} + +// addSheetPicture provides a function to add picture element to +// xl/worksheets/sheet%d.xml by given worksheet name and relationship index. +func (f *File) addSheetPicture(sheet string, rID int) { + xlsx := f.workSheetReader(sheet) + xlsx.Picture = &xlsxPicture{ + RID: "rId" + strconv.Itoa(rID), + } +} + +// countDrawings provides a function to get drawing files count storage in the +// folder xl/drawings. +func (f *File) countDrawings() int { + count := 0 + for k := range f.XLSX { + if strings.Contains(k, "xl/drawings/drawing") { + count++ + } + } + return count +} + +// addDrawingPicture provides a function to add picture by given sheet, +// drawingXML, cell, file name, width, height relationship index and format +// sets. +func (f *File) addDrawingPicture(sheet, drawingXML, cell, file string, width, height, rID, hyperlinkRID int, formatSet *formatPicture) { + cell = strings.ToUpper(cell) + fromCol := string(strings.Map(letterOnlyMapF, cell)) + fromRow, _ := strconv.Atoi(strings.Map(intOnlyMapF, cell)) + row := fromRow - 1 + col := TitleToNumber(fromCol) + width = int(float64(width) * formatSet.XScale) + height = int(float64(height) * formatSet.YScale) + colStart, rowStart, _, _, colEnd, rowEnd, x2, y2 := f.positionObjectPixels(sheet, col, row, formatSet.OffsetX, formatSet.OffsetY, width, height) + content := xlsxWsDr{} + content.A = NameSpaceDrawingML + content.Xdr = NameSpaceDrawingMLSpreadSheet + cNvPrID := f.drawingParser(drawingXML, &content) + twoCellAnchor := xdrCellAnchor{} + twoCellAnchor.EditAs = formatSet.Positioning + from := xlsxFrom{} + from.Col = colStart + from.ColOff = formatSet.OffsetX * EMU + from.Row = rowStart + from.RowOff = formatSet.OffsetY * EMU + to := xlsxTo{} + to.Col = colEnd + to.ColOff = x2 * EMU + to.Row = rowEnd + to.RowOff = y2 * EMU + twoCellAnchor.From = &from + twoCellAnchor.To = &to + pic := xlsxPic{} + pic.NvPicPr.CNvPicPr.PicLocks.NoChangeAspect = formatSet.NoChangeAspect + pic.NvPicPr.CNvPr.ID = f.countCharts() + f.countMedia() + 1 + pic.NvPicPr.CNvPr.Descr = file + pic.NvPicPr.CNvPr.Name = "Picture " + strconv.Itoa(cNvPrID) + if hyperlinkRID != 0 { + pic.NvPicPr.CNvPr.HlinkClick = &xlsxHlinkClick{ + R: SourceRelationship, + RID: "rId" + strconv.Itoa(hyperlinkRID), + } + } + pic.BlipFill.Blip.R = SourceRelationship + pic.BlipFill.Blip.Embed = "rId" + strconv.Itoa(rID) + pic.SpPr.PrstGeom.Prst = "rect" + + twoCellAnchor.Pic = &pic + twoCellAnchor.ClientData = &xdrClientData{ + FLocksWithSheet: formatSet.FLocksWithSheet, + FPrintsWithSheet: formatSet.FPrintsWithSheet, + } + content.TwoCellAnchor = append(content.TwoCellAnchor, &twoCellAnchor) + output, _ := xml.Marshal(content) + f.saveFileList(drawingXML, output) +} + +// addDrawingRelationships provides a function to add image part relationships +// in the file xl/drawings/_rels/drawing%d.xml.rels by given drawing index, +// relationship type and target. +func (f *File) addDrawingRelationships(index int, relType, target, targetMode string) int { + var rels = "xl/drawings/_rels/drawing" + strconv.Itoa(index) + ".xml.rels" + var drawingRels xlsxWorkbookRels + var rID = 1 + var ID bytes.Buffer + ID.WriteString("rId") + ID.WriteString(strconv.Itoa(rID)) + _, ok := f.XLSX[rels] + if ok { + ID.Reset() + _ = xml.Unmarshal(namespaceStrictToTransitional(f.readXML(rels)), &drawingRels) + rID = len(drawingRels.Relationships) + 1 + ID.WriteString("rId") + ID.WriteString(strconv.Itoa(rID)) + } + drawingRels.Relationships = append(drawingRels.Relationships, xlsxWorkbookRelation{ + ID: ID.String(), + Type: relType, + Target: target, + TargetMode: targetMode, + }) + output, _ := xml.Marshal(drawingRels) + f.saveFileList(rels, output) + return rID +} + +// countMedia provides a function to get media files count storage in the +// folder xl/media/image. +func (f *File) countMedia() int { + count := 0 + for k := range f.XLSX { + if strings.Contains(k, "xl/media/image") { + count++ + } + } + return count +} + +// addMedia provides a function to add picture into folder xl/media/image by +// given file and extension name. +func (f *File) addMedia(file []byte, ext string) { + count := f.countMedia() + media := "xl/media/image" + strconv.Itoa(count+1) + ext + f.XLSX[media] = file +} + +// setContentTypePartImageExtensions provides a function to set the content +// type for relationship parts and the Main Document part. +func (f *File) setContentTypePartImageExtensions() { + var imageTypes = map[string]bool{"jpeg": false, "png": false, "gif": false} + content := f.contentTypesReader() + for _, v := range content.Defaults { + _, ok := imageTypes[v.Extension] + if ok { + imageTypes[v.Extension] = true + } + } + for k, v := range imageTypes { + if !v { + content.Defaults = append(content.Defaults, xlsxDefault{ + Extension: k, + ContentType: "image/" + k, + }) + } + } +} + +// setContentTypePartVMLExtensions provides a function to set the content type +// for relationship parts and the Main Document part. +func (f *File) setContentTypePartVMLExtensions() { + vml := false + content := f.contentTypesReader() + for _, v := range content.Defaults { + if v.Extension == "vml" { + vml = true + } + } + if !vml { + content.Defaults = append(content.Defaults, xlsxDefault{ + Extension: "vml", + ContentType: "application/vnd.openxmlformats-officedocument.vmlDrawing", + }) + } +} + +// addContentTypePart provides a function to add content type part +// relationships in the file [Content_Types].xml by given index. +func (f *File) addContentTypePart(index int, contentType string) { + setContentType := map[string]func(){ + "comments": f.setContentTypePartVMLExtensions, + "drawings": f.setContentTypePartImageExtensions, + } + partNames := map[string]string{ + "chart": "/xl/charts/chart" + strconv.Itoa(index) + ".xml", + "comments": "/xl/comments" + strconv.Itoa(index) + ".xml", + "drawings": "/xl/drawings/drawing" + strconv.Itoa(index) + ".xml", + "table": "/xl/tables/table" + strconv.Itoa(index) + ".xml", + } + contentTypes := map[string]string{ + "chart": "application/vnd.openxmlformats-officedocument.drawingml.chart+xml", + "comments": "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml", + "drawings": "application/vnd.openxmlformats-officedocument.drawing+xml", + "table": "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml", + } + s, ok := setContentType[contentType] + if ok { + s() + } + content := f.contentTypesReader() + for _, v := range content.Overrides { + if v.PartName == partNames[contentType] { + return + } + } + content.Overrides = append(content.Overrides, xlsxOverride{ + PartName: partNames[contentType], + ContentType: contentTypes[contentType], + }) +} + +// getSheetRelationshipsTargetByID provides a function to get Target attribute +// value in xl/worksheets/_rels/sheet%d.xml.rels by given worksheet name and +// relationship index. +func (f *File) getSheetRelationshipsTargetByID(sheet, rID string) string { + name, ok := f.sheetMap[trimSheetName(sheet)] + if !ok { + name = strings.ToLower(sheet) + ".xml" + } + var rels = "xl/worksheets/_rels/" + strings.TrimPrefix(name, "xl/worksheets/") + ".rels" + var sheetRels xlsxWorkbookRels + _ = xml.Unmarshal(namespaceStrictToTransitional(f.readXML(rels)), &sheetRels) + for _, v := range sheetRels.Relationships { + if v.ID == rID { + return v.Target + } + } + return "" +} + +// GetPicture provides a function to get picture base name and raw content +// embed in XLSX by given worksheet and cell name. This function returns the +// file name in XLSX and file contents as []byte data types. For example: +// +// xlsx, err := excelize.OpenFile("./Book1.xlsx") +// if err != nil { +// fmt.Println(err) +// return +// } +// file, raw := xlsx.GetPicture("Sheet1", "A2") +// if file == "" { +// return +// } +// err := ioutil.WriteFile(file, raw, 0644) +// if err != nil { +// fmt.Println(err) +// } +// +func (f *File) GetPicture(sheet, cell string) (string, []byte) { + xlsx := f.workSheetReader(sheet) + if xlsx.Drawing == nil { + return "", []byte{} + } + target := f.getSheetRelationshipsTargetByID(sheet, xlsx.Drawing.RID) + drawingXML := strings.Replace(target, "..", "xl", -1) + + _, ok := f.XLSX[drawingXML] + if !ok { + return "", nil + } + decodeWsDr := decodeWsDr{} + _ = xml.Unmarshal(namespaceStrictToTransitional(f.readXML(drawingXML)), &decodeWsDr) + + cell = strings.ToUpper(cell) + fromCol := string(strings.Map(letterOnlyMapF, cell)) + fromRow, _ := strconv.Atoi(strings.Map(intOnlyMapF, cell)) + row := fromRow - 1 + col := TitleToNumber(fromCol) + + drawingRelationships := strings.Replace(strings.Replace(target, "../drawings", "xl/drawings/_rels", -1), ".xml", ".xml.rels", -1) + + for _, anchor := range decodeWsDr.TwoCellAnchor { + decodeTwoCellAnchor := decodeTwoCellAnchor{} + _ = xml.Unmarshal([]byte(""+anchor.Content+""), &decodeTwoCellAnchor) + if decodeTwoCellAnchor.From != nil && decodeTwoCellAnchor.Pic != nil { + if decodeTwoCellAnchor.From.Col == col && decodeTwoCellAnchor.From.Row == row { + xlsxWorkbookRelation := f.getDrawingRelationships(drawingRelationships, decodeTwoCellAnchor.Pic.BlipFill.Blip.Embed) + _, ok := supportImageTypes[filepath.Ext(xlsxWorkbookRelation.Target)] + if ok { + return filepath.Base(xlsxWorkbookRelation.Target), []byte(f.XLSX[strings.Replace(xlsxWorkbookRelation.Target, "..", "xl", -1)]) + } + } + } + } + return "", []byte{} +} + +// getDrawingRelationships provides a function to get drawing relationships +// from xl/drawings/_rels/drawing%s.xml.rels by given file name and +// relationship ID. +func (f *File) getDrawingRelationships(rels, rID string) *xlsxWorkbookRelation { + _, ok := f.XLSX[rels] + if !ok { + return nil + } + var drawingRels xlsxWorkbookRels + _ = xml.Unmarshal(namespaceStrictToTransitional(f.readXML(rels)), &drawingRels) + for _, v := range drawingRels.Relationships { + if v.ID == rID { + return &v + } + } + return nil +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/rows.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/rows.go new file mode 100644 index 0000000000..d3fe6e0994 --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/rows.go @@ -0,0 +1,510 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. + +package excelize + +import ( + "bytes" + "encoding/xml" + "fmt" + "io" + "math" + "strconv" + "strings" +) + +// GetRows return all the rows in a sheet by given worksheet name (case +// sensitive). For example: +// +// for _, row := range xlsx.GetRows("Sheet1") { +// for _, colCell := range row { +// fmt.Print(colCell, "\t") +// } +// fmt.Println() +// } +// +func (f *File) GetRows(sheet string) [][]string { + xlsx := f.workSheetReader(sheet) + name, ok := f.sheetMap[trimSheetName(sheet)] + if !ok { + return [][]string{} + } + if xlsx != nil { + output, _ := xml.Marshal(f.Sheet[name]) + f.saveFileList(name, replaceWorkSheetsRelationshipsNameSpaceBytes(output)) + } + xml.NewDecoder(bytes.NewReader(f.readXML(name))) + d := f.sharedStringsReader() + var inElement string + var r xlsxRow + tr, tc := f.getTotalRowsCols(name) + rows := make([][]string, tr) + for i := range rows { + rows[i] = make([]string, tc+1) + } + var row int + decoder := xml.NewDecoder(bytes.NewReader(f.readXML(name))) + for { + token, _ := decoder.Token() + if token == nil { + break + } + switch startElement := token.(type) { + case xml.StartElement: + inElement = startElement.Name.Local + if inElement == "row" { + r = xlsxRow{} + _ = decoder.DecodeElement(&r, &startElement) + cr := r.R - 1 + for _, colCell := range r.C { + c := TitleToNumber(strings.Map(letterOnlyMapF, colCell.R)) + val, _ := colCell.getValueFrom(f, d) + rows[cr][c] = val + if val != "" { + row = r.R + } + } + } + default: + } + } + return rows[:row] +} + +// Rows defines an iterator to a sheet +type Rows struct { + decoder *xml.Decoder + token xml.Token + err error + f *File +} + +// Next will return true if find the next row element. +func (rows *Rows) Next() bool { + for { + rows.token, rows.err = rows.decoder.Token() + if rows.err == io.EOF { + rows.err = nil + } + if rows.token == nil { + return false + } + + switch startElement := rows.token.(type) { + case xml.StartElement: + inElement := startElement.Name.Local + if inElement == "row" { + return true + } + } + } +} + +// Error will return the error when the find next row element +func (rows *Rows) Error() error { + return rows.err +} + +// Columns return the current row's column values +func (rows *Rows) Columns() []string { + if rows.token == nil { + return []string{} + } + startElement := rows.token.(xml.StartElement) + r := xlsxRow{} + _ = rows.decoder.DecodeElement(&r, &startElement) + d := rows.f.sharedStringsReader() + row := make([]string, len(r.C)) + for _, colCell := range r.C { + c := TitleToNumber(strings.Map(letterOnlyMapF, colCell.R)) + val, _ := colCell.getValueFrom(rows.f, d) + row[c] = val + } + return row +} + +// ErrSheetNotExist defines an error of sheet is not exist +type ErrSheetNotExist struct { + SheetName string +} + +func (err ErrSheetNotExist) Error() string { + return fmt.Sprintf("Sheet %s is not exist", string(err.SheetName)) +} + +// Rows return a rows iterator. For example: +// +// rows, err := xlsx.Rows("Sheet1") +// for rows.Next() { +// for _, colCell := range rows.Columns() { +// fmt.Print(colCell, "\t") +// } +// fmt.Println() +// } +// +func (f *File) Rows(sheet string) (*Rows, error) { + xlsx := f.workSheetReader(sheet) + name, ok := f.sheetMap[trimSheetName(sheet)] + if !ok { + return nil, ErrSheetNotExist{sheet} + } + if xlsx != nil { + output, _ := xml.Marshal(f.Sheet[name]) + f.saveFileList(name, replaceWorkSheetsRelationshipsNameSpaceBytes(output)) + } + return &Rows{ + f: f, + decoder: xml.NewDecoder(bytes.NewReader(f.readXML(name))), + }, nil +} + +// getTotalRowsCols provides a function to get total columns and rows in a +// worksheet. +func (f *File) getTotalRowsCols(name string) (int, int) { + decoder := xml.NewDecoder(bytes.NewReader(f.readXML(name))) + var inElement string + var r xlsxRow + var tr, tc int + for { + token, _ := decoder.Token() + if token == nil { + break + } + switch startElement := token.(type) { + case xml.StartElement: + inElement = startElement.Name.Local + if inElement == "row" { + r = xlsxRow{} + _ = decoder.DecodeElement(&r, &startElement) + tr = r.R + for _, colCell := range r.C { + col := TitleToNumber(strings.Map(letterOnlyMapF, colCell.R)) + if col > tc { + tc = col + } + } + } + default: + } + } + return tr, tc +} + +// SetRowHeight provides a function to set the height of a single row. For +// example, set the height of the first row in Sheet1: +// +// xlsx.SetRowHeight("Sheet1", 1, 50) +// +func (f *File) SetRowHeight(sheet string, row int, height float64) { + xlsx := f.workSheetReader(sheet) + cells := 0 + rowIdx := row - 1 + completeRow(xlsx, row, cells) + xlsx.SheetData.Row[rowIdx].Ht = height + xlsx.SheetData.Row[rowIdx].CustomHeight = true +} + +// getRowHeight provides a function to get row height in pixels by given sheet +// name and row index. +func (f *File) getRowHeight(sheet string, row int) int { + xlsx := f.workSheetReader(sheet) + for _, v := range xlsx.SheetData.Row { + if v.R == row+1 && v.Ht != 0 { + return int(convertRowHeightToPixels(v.Ht)) + } + } + // Optimisation for when the row heights haven't changed. + return int(defaultRowHeightPixels) +} + +// GetRowHeight provides a function to get row height by given worksheet name +// and row index. For example, get the height of the first row in Sheet1: +// +// xlsx.GetRowHeight("Sheet1", 1) +// +func (f *File) GetRowHeight(sheet string, row int) float64 { + xlsx := f.workSheetReader(sheet) + for _, v := range xlsx.SheetData.Row { + if v.R == row && v.Ht != 0 { + return v.Ht + } + } + // Optimisation for when the row heights haven't changed. + return defaultRowHeightPixels +} + +// sharedStringsReader provides a function to get the pointer to the structure +// after deserialization of xl/sharedStrings.xml. +func (f *File) sharedStringsReader() *xlsxSST { + if f.SharedStrings == nil { + var sharedStrings xlsxSST + ss := f.readXML("xl/sharedStrings.xml") + if len(ss) == 0 { + ss = f.readXML("xl/SharedStrings.xml") + } + _ = xml.Unmarshal(namespaceStrictToTransitional(ss), &sharedStrings) + f.SharedStrings = &sharedStrings + } + return f.SharedStrings +} + +// getValueFrom return a value from a column/row cell, this function is +// inteded to be used with for range on rows an argument with the xlsx opened +// file. +func (xlsx *xlsxC) getValueFrom(f *File, d *xlsxSST) (string, error) { + switch xlsx.T { + case "s": + xlsxSI := 0 + xlsxSI, _ = strconv.Atoi(xlsx.V) + if len(d.SI[xlsxSI].R) > 0 { + value := "" + for _, v := range d.SI[xlsxSI].R { + value += v.T + } + return value, nil + } + return f.formattedValue(xlsx.S, d.SI[xlsxSI].T), nil + case "str": + return f.formattedValue(xlsx.S, xlsx.V), nil + case "inlineStr": + return f.formattedValue(xlsx.S, xlsx.IS.T), nil + default: + return f.formattedValue(xlsx.S, xlsx.V), nil + } +} + +// SetRowVisible provides a function to set visible of a single row by given +// worksheet name and row index. For example, hide row 2 in Sheet1: +// +// xlsx.SetRowVisible("Sheet1", 2, false) +// +func (f *File) SetRowVisible(sheet string, rowIndex int, visible bool) { + xlsx := f.workSheetReader(sheet) + rows := rowIndex + 1 + cells := 0 + completeRow(xlsx, rows, cells) + if visible { + xlsx.SheetData.Row[rowIndex].Hidden = false + return + } + xlsx.SheetData.Row[rowIndex].Hidden = true +} + +// GetRowVisible provides a function to get visible of a single row by given +// worksheet name and row index. For example, get visible state of row 2 in +// Sheet1: +// +// xlsx.GetRowVisible("Sheet1", 2) +// +func (f *File) GetRowVisible(sheet string, rowIndex int) bool { + xlsx := f.workSheetReader(sheet) + rows := rowIndex + 1 + cells := 0 + completeRow(xlsx, rows, cells) + return !xlsx.SheetData.Row[rowIndex].Hidden +} + +// SetRowOutlineLevel provides a function to set outline level number of a +// single row by given worksheet name and row index. For example, outline row +// 2 in Sheet1 to level 1: +// +// xlsx.SetRowOutlineLevel("Sheet1", 2, 1) +// +func (f *File) SetRowOutlineLevel(sheet string, rowIndex int, level uint8) { + xlsx := f.workSheetReader(sheet) + rows := rowIndex + 1 + cells := 0 + completeRow(xlsx, rows, cells) + xlsx.SheetData.Row[rowIndex].OutlineLevel = level +} + +// GetRowOutlineLevel provides a function to get outline level number of a +// single row by given worksheet name and row index. For example, get outline +// number of row 2 in Sheet1: +// +// xlsx.GetRowOutlineLevel("Sheet1", 2) +// +func (f *File) GetRowOutlineLevel(sheet string, rowIndex int) uint8 { + xlsx := f.workSheetReader(sheet) + rows := rowIndex + 1 + cells := 0 + completeRow(xlsx, rows, cells) + return xlsx.SheetData.Row[rowIndex].OutlineLevel +} + +// RemoveRow provides a function to remove single row by given worksheet name +// and row index. For example, remove row 3 in Sheet1: +// +// xlsx.RemoveRow("Sheet1", 2) +// +func (f *File) RemoveRow(sheet string, row int) { + if row < 0 { + return + } + xlsx := f.workSheetReader(sheet) + row++ + for i, r := range xlsx.SheetData.Row { + if r.R == row { + xlsx.SheetData.Row = append(xlsx.SheetData.Row[:i], xlsx.SheetData.Row[i+1:]...) + f.adjustHelper(sheet, -1, row, -1) + return + } + } +} + +// InsertRow provides a function to insert a new row after given row index. +// For example, create a new row before row 3 in Sheet1: +// +// xlsx.InsertRow("Sheet1", 2) +// +func (f *File) InsertRow(sheet string, row int) { + if row < 0 { + return + } + row++ + f.adjustHelper(sheet, -1, row, 1) +} + +// DuplicateRow inserts a copy of specified row below specified +// +// xlsx.DuplicateRow("Sheet1", 2) +// +func (f *File) DuplicateRow(sheet string, row int) { + if row < 0 { + return + } + row2 := row + 1 + f.adjustHelper(sheet, -1, row2, 1) + + xlsx := f.workSheetReader(sheet) + idx := -1 + idx2 := -1 + + for i, r := range xlsx.SheetData.Row { + if r.R == row { + idx = i + } else if r.R == row2 { + idx2 = i + } + if idx != -1 && idx2 != -1 { + break + } + } + + if idx == -1 || (idx2 == -1 && len(xlsx.SheetData.Row) >= row2) { + return + } + rowData := xlsx.SheetData.Row[idx] + cols := make([]xlsxC, 0, len(rowData.C)) + rowData.C = append(cols, rowData.C...) + f.ajustSingleRowDimensions(&rowData, 1) + if idx2 != -1 { + xlsx.SheetData.Row[idx2] = rowData + } else { + xlsx.SheetData.Row = append(xlsx.SheetData.Row, rowData) + } +} + +// checkRow provides a function to check and fill each column element for all +// rows and make that is continuous in a worksheet of XML. For example: +// +// +// +// +// +// +// +// +// in this case, we should to change it to +// +// +// +// +// +// +// +// +// +// +// +// Noteice: this method could be very slow for large spreadsheets (more than +// 3000 rows one sheet). +func checkRow(xlsx *xlsxWorksheet) { + buffer := bytes.Buffer{} + for k := range xlsx.SheetData.Row { + lenCol := len(xlsx.SheetData.Row[k].C) + if lenCol > 0 { + endR := string(strings.Map(letterOnlyMapF, xlsx.SheetData.Row[k].C[lenCol-1].R)) + endRow, _ := strconv.Atoi(strings.Map(intOnlyMapF, xlsx.SheetData.Row[k].C[lenCol-1].R)) + endCol := TitleToNumber(endR) + 1 + if lenCol < endCol { + oldRow := xlsx.SheetData.Row[k].C + xlsx.SheetData.Row[k].C = xlsx.SheetData.Row[k].C[:0] + tmp := []xlsxC{} + for i := 0; i < endCol; i++ { + buffer.WriteString(ToAlphaString(i)) + buffer.WriteString(strconv.Itoa(endRow)) + tmp = append(tmp, xlsxC{ + R: buffer.String(), + }) + buffer.Reset() + } + xlsx.SheetData.Row[k].C = tmp + for _, y := range oldRow { + colAxis := TitleToNumber(string(strings.Map(letterOnlyMapF, y.R))) + xlsx.SheetData.Row[k].C[colAxis] = y + } + } + } + } +} + +// completeRow provides a function to check and fill each column element for a +// single row and make that is continuous in a worksheet of XML by given row +// index and axis. +func completeRow(xlsx *xlsxWorksheet, row, cell int) { + currentRows := len(xlsx.SheetData.Row) + if currentRows > 1 { + lastRow := xlsx.SheetData.Row[currentRows-1].R + if lastRow >= row { + row = lastRow + } + } + for i := currentRows; i < row; i++ { + xlsx.SheetData.Row = append(xlsx.SheetData.Row, xlsxRow{ + R: i + 1, + }) + } + buffer := bytes.Buffer{} + for ii := currentRows; ii < row; ii++ { + start := len(xlsx.SheetData.Row[ii].C) + if start == 0 { + for iii := start; iii < cell; iii++ { + buffer.WriteString(ToAlphaString(iii)) + buffer.WriteString(strconv.Itoa(ii + 1)) + xlsx.SheetData.Row[ii].C = append(xlsx.SheetData.Row[ii].C, xlsxC{ + R: buffer.String(), + }) + buffer.Reset() + } + } + } +} + +// convertRowHeightToPixels provides a function to convert the height of a +// cell from user's units to pixels. If the height hasn't been set by the user +// we use the default value. If the row is hidden it has a value of zero. +func convertRowHeightToPixels(height float64) float64 { + var pixels float64 + if height == 0 { + return pixels + } + pixels = math.Ceil(4.0 / 3.0 * height) + return pixels +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/shape.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/shape.go new file mode 100644 index 0000000000..e2281a23ce --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/shape.go @@ -0,0 +1,428 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. + +package excelize + +import ( + "encoding/json" + "encoding/xml" + "strconv" + "strings" +) + +// parseFormatShapeSet provides a function to parse the format settings of the +// shape with default value. +func parseFormatShapeSet(formatSet string) (*formatShape, error) { + format := formatShape{ + Width: 160, + Height: 160, + Format: formatPicture{ + FPrintsWithSheet: true, + FLocksWithSheet: false, + NoChangeAspect: false, + OffsetX: 0, + OffsetY: 0, + XScale: 1.0, + YScale: 1.0, + }, + } + err := json.Unmarshal([]byte(formatSet), &format) + return &format, err +} + +// AddShape provides the method to add shape in a sheet by given worksheet +// index, shape format set (such as offset, scale, aspect ratio setting and +// print settings) and properties set. For example, add text box (rect shape) +// in Sheet1: +// +// xlsx.AddShape("Sheet1", "G6", `{"type":"rect","color":{"line":"#4286F4","fill":"#8eb9ff"},"paragraph":[{"text":"Rectangle Shape","font":{"bold":true,"italic":true,"family":"Berlin Sans FB Demi","size":36,"color":"#777777","underline":"sng"}}],"width":180,"height": 90}`) +// +// The following shows the type of shape supported by excelize: +// +// accentBorderCallout1 (Callout 1 with Border and Accent Shape) +// accentBorderCallout2 (Callout 2 with Border and Accent Shape) +// accentBorderCallout3 (Callout 3 with Border and Accent Shape) +// accentCallout1 (Callout 1 Shape) +// accentCallout2 (Callout 2 Shape) +// accentCallout3 (Callout 3 Shape) +// actionButtonBackPrevious (Back or Previous Button Shape) +// actionButtonBeginning (Beginning Button Shape) +// actionButtonBlank (Blank Button Shape) +// actionButtonDocument (Document Button Shape) +// actionButtonEnd (End Button Shape) +// actionButtonForwardNext (Forward or Next Button Shape) +// actionButtonHelp (Help Button Shape) +// actionButtonHome (Home Button Shape) +// actionButtonInformation (Information Button Shape) +// actionButtonMovie (Movie Button Shape) +// actionButtonReturn (Return Button Shape) +// actionButtonSound (Sound Button Shape) +// arc (Curved Arc Shape) +// bentArrow (Bent Arrow Shape) +// bentConnector2 (Bent Connector 2 Shape) +// bentConnector3 (Bent Connector 3 Shape) +// bentConnector4 (Bent Connector 4 Shape) +// bentConnector5 (Bent Connector 5 Shape) +// bentUpArrow (Bent Up Arrow Shape) +// bevel (Bevel Shape) +// blockArc (Block Arc Shape) +// borderCallout1 (Callout 1 with Border Shape) +// borderCallout2 (Callout 2 with Border Shape) +// borderCallout3 (Callout 3 with Border Shape) +// bracePair (Brace Pair Shape) +// bracketPair (Bracket Pair Shape) +// callout1 (Callout 1 Shape) +// callout2 (Callout 2 Shape) +// callout3 (Callout 3 Shape) +// can (Can Shape) +// chartPlus (Chart Plus Shape) +// chartStar (Chart Star Shape) +// chartX (Chart X Shape) +// chevron (Chevron Shape) +// chord (Chord Shape) +// circularArrow (Circular Arrow Shape) +// cloud (Cloud Shape) +// cloudCallout (Callout Cloud Shape) +// corner (Corner Shape) +// cornerTabs (Corner Tabs Shape) +// cube (Cube Shape) +// curvedConnector2 (Curved Connector 2 Shape) +// curvedConnector3 (Curved Connector 3 Shape) +// curvedConnector4 (Curved Connector 4 Shape) +// curvedConnector5 (Curved Connector 5 Shape) +// curvedDownArrow (Curved Down Arrow Shape) +// curvedLeftArrow (Curved Left Arrow Shape) +// curvedRightArrow (Curved Right Arrow Shape) +// curvedUpArrow (Curved Up Arrow Shape) +// decagon (Decagon Shape) +// diagStripe (Diagonal Stripe Shape) +// diamond (Diamond Shape) +// dodecagon (Dodecagon Shape) +// donut (Donut Shape) +// doubleWave (Double Wave Shape) +// downArrow (Down Arrow Shape) +// downArrowCallout (Callout Down Arrow Shape) +// ellipse (Ellipse Shape) +// ellipseRibbon (Ellipse Ribbon Shape) +// ellipseRibbon2 (Ellipse Ribbon 2 Shape) +// flowChartAlternateProcess (Alternate Process Flow Shape) +// flowChartCollate (Collate Flow Shape) +// flowChartConnector (Connector Flow Shape) +// flowChartDecision (Decision Flow Shape) +// flowChartDelay (Delay Flow Shape) +// flowChartDisplay (Display Flow Shape) +// flowChartDocument (Document Flow Shape) +// flowChartExtract (Extract Flow Shape) +// flowChartInputOutput (Input Output Flow Shape) +// flowChartInternalStorage (Internal Storage Flow Shape) +// flowChartMagneticDisk (Magnetic Disk Flow Shape) +// flowChartMagneticDrum (Magnetic Drum Flow Shape) +// flowChartMagneticTape (Magnetic Tape Flow Shape) +// flowChartManualInput (Manual Input Flow Shape) +// flowChartManualOperation (Manual Operation Flow Shape) +// flowChartMerge (Merge Flow Shape) +// flowChartMultidocument (Multi-Document Flow Shape) +// flowChartOfflineStorage (Offline Storage Flow Shape) +// flowChartOffpageConnector (Off-Page Connector Flow Shape) +// flowChartOnlineStorage (Online Storage Flow Shape) +// flowChartOr (Or Flow Shape) +// flowChartPredefinedProcess (Predefined Process Flow Shape) +// flowChartPreparation (Preparation Flow Shape) +// flowChartProcess (Process Flow Shape) +// flowChartPunchedCard (Punched Card Flow Shape) +// flowChartPunchedTape (Punched Tape Flow Shape) +// flowChartSort (Sort Flow Shape) +// flowChartSummingJunction (Summing Junction Flow Shape) +// flowChartTerminator (Terminator Flow Shape) +// foldedCorner (Folded Corner Shape) +// frame (Frame Shape) +// funnel (Funnel Shape) +// gear6 (Gear 6 Shape) +// gear9 (Gear 9 Shape) +// halfFrame (Half Frame Shape) +// heart (Heart Shape) +// heptagon (Heptagon Shape) +// hexagon (Hexagon Shape) +// homePlate (Home Plate Shape) +// horizontalScroll (Horizontal Scroll Shape) +// irregularSeal1 (Irregular Seal 1 Shape) +// irregularSeal2 (Irregular Seal 2 Shape) +// leftArrow (Left Arrow Shape) +// leftArrowCallout (Callout Left Arrow Shape) +// leftBrace (Left Brace Shape) +// leftBracket (Left Bracket Shape) +// leftCircularArrow (Left Circular Arrow Shape) +// leftRightArrow (Left Right Arrow Shape) +// leftRightArrowCallout (Callout Left Right Arrow Shape) +// leftRightCircularArrow (Left Right Circular Arrow Shape) +// leftRightRibbon (Left Right Ribbon Shape) +// leftRightUpArrow (Left Right Up Arrow Shape) +// leftUpArrow (Left Up Arrow Shape) +// lightningBolt (Lightning Bolt Shape) +// line (Line Shape) +// lineInv (Line Inverse Shape) +// mathDivide (Divide Math Shape) +// mathEqual (Equal Math Shape) +// mathMinus (Minus Math Shape) +// mathMultiply (Multiply Math Shape) +// mathNotEqual (Not Equal Math Shape) +// mathPlus (Plus Math Shape) +// moon (Moon Shape) +// nonIsoscelesTrapezoid (Non-Isosceles Trapezoid Shape) +// noSmoking (No Smoking Shape) +// notchedRightArrow (Notched Right Arrow Shape) +// octagon (Octagon Shape) +// parallelogram (Parallelogram Shape) +// pentagon (Pentagon Shape) +// pie (Pie Shape) +// pieWedge (Pie Wedge Shape) +// plaque (Plaque Shape) +// plaqueTabs (Plaque Tabs Shape) +// plus (Plus Shape) +// quadArrow (Quad-Arrow Shape) +// quadArrowCallout (Callout Quad-Arrow Shape) +// rect (Rectangle Shape) +// ribbon (Ribbon Shape) +// ribbon2 (Ribbon 2 Shape) +// rightArrow (Right Arrow Shape) +// rightArrowCallout (Callout Right Arrow Shape) +// rightBrace (Right Brace Shape) +// rightBracket (Right Bracket Shape) +// round1Rect (One Round Corner Rectangle Shape) +// round2DiagRect (Two Diagonal Round Corner Rectangle Shape) +// round2SameRect (Two Same-side Round Corner Rectangle Shape) +// roundRect (Round Corner Rectangle Shape) +// rtTriangle (Right Triangle Shape) +// smileyFace (Smiley Face Shape) +// snip1Rect (One Snip Corner Rectangle Shape) +// snip2DiagRect (Two Diagonal Snip Corner Rectangle Shape) +// snip2SameRect (Two Same-side Snip Corner Rectangle Shape) +// snipRoundRect (One Snip One Round Corner Rectangle Shape) +// squareTabs (Square Tabs Shape) +// star10 (Ten Pointed Star Shape) +// star12 (Twelve Pointed Star Shape) +// star16 (Sixteen Pointed Star Shape) +// star24 (Twenty Four Pointed Star Shape) +// star32 (Thirty Two Pointed Star Shape) +// star4 (Four Pointed Star Shape) +// star5 (Five Pointed Star Shape) +// star6 (Six Pointed Star Shape) +// star7 (Seven Pointed Star Shape) +// star8 (Eight Pointed Star Shape) +// straightConnector1 (Straight Connector 1 Shape) +// stripedRightArrow (Striped Right Arrow Shape) +// sun (Sun Shape) +// swooshArrow (Swoosh Arrow Shape) +// teardrop (Teardrop Shape) +// trapezoid (Trapezoid Shape) +// triangle (Triangle Shape) +// upArrow (Up Arrow Shape) +// upArrowCallout (Callout Up Arrow Shape) +// upDownArrow (Up Down Arrow Shape) +// upDownArrowCallout (Callout Up Down Arrow Shape) +// uturnArrow (U-Turn Arrow Shape) +// verticalScroll (Vertical Scroll Shape) +// wave (Wave Shape) +// wedgeEllipseCallout (Callout Wedge Ellipse Shape) +// wedgeRectCallout (Callout Wedge Rectangle Shape) +// wedgeRoundRectCallout (Callout Wedge Round Rectangle Shape) +// +// The following shows the type of text underline supported by excelize: +// +// none +// words +// sng +// dbl +// heavy +// dotted +// dottedHeavy +// dash +// dashHeavy +// dashLong +// dashLongHeavy +// dotDash +// dotDashHeavy +// dotDotDash +// dotDotDashHeavy +// wavy +// wavyHeavy +// wavyDbl +// +func (f *File) AddShape(sheet, cell, format string) error { + formatSet, err := parseFormatShapeSet(format) + if err != nil { + return err + } + // Read sheet data. + xlsx := f.workSheetReader(sheet) + // Add first shape for given sheet, create xl/drawings/ and xl/drawings/_rels/ folder. + drawingID := f.countDrawings() + 1 + drawingXML := "xl/drawings/drawing" + strconv.Itoa(drawingID) + ".xml" + sheetRelationshipsDrawingXML := "../drawings/drawing" + strconv.Itoa(drawingID) + ".xml" + + if xlsx.Drawing != nil { + // The worksheet already has a shape or chart relationships, use the relationships drawing ../drawings/drawing%d.xml. + sheetRelationshipsDrawingXML = f.getSheetRelationshipsTargetByID(sheet, xlsx.Drawing.RID) + drawingID, _ = strconv.Atoi(strings.TrimSuffix(strings.TrimPrefix(sheetRelationshipsDrawingXML, "../drawings/drawing"), ".xml")) + drawingXML = strings.Replace(sheetRelationshipsDrawingXML, "..", "xl", -1) + } else { + // Add first shape for given sheet. + rID := f.addSheetRelationships(sheet, SourceRelationshipDrawingML, sheetRelationshipsDrawingXML, "") + f.addSheetDrawing(sheet, rID) + } + f.addDrawingShape(sheet, drawingXML, cell, formatSet) + f.addContentTypePart(drawingID, "drawings") + return err +} + +// addDrawingShape provides a function to add preset geometry by given sheet, +// drawingXMLand format sets. +func (f *File) addDrawingShape(sheet, drawingXML, cell string, formatSet *formatShape) { + textUnderlineType := map[string]bool{"none": true, "words": true, "sng": true, "dbl": true, "heavy": true, "dotted": true, "dottedHeavy": true, "dash": true, "dashHeavy": true, "dashLong": true, "dashLongHeavy": true, "dotDash": true, "dotDashHeavy": true, "dotDotDash": true, "dotDotDashHeavy": true, "wavy": true, "wavyHeavy": true, "wavyDbl": true} + cell = strings.ToUpper(cell) + fromCol := string(strings.Map(letterOnlyMapF, cell)) + fromRow, _ := strconv.Atoi(strings.Map(intOnlyMapF, cell)) + row := fromRow - 1 + col := TitleToNumber(fromCol) + width := int(float64(formatSet.Width) * formatSet.Format.XScale) + height := int(float64(formatSet.Height) * formatSet.Format.YScale) + colStart, rowStart, _, _, colEnd, rowEnd, x2, y2 := f.positionObjectPixels(sheet, col, row, formatSet.Format.OffsetX, formatSet.Format.OffsetY, width, height) + content := xlsxWsDr{} + content.A = NameSpaceDrawingML + content.Xdr = NameSpaceDrawingMLSpreadSheet + cNvPrID := f.drawingParser(drawingXML, &content) + twoCellAnchor := xdrCellAnchor{} + twoCellAnchor.EditAs = formatSet.Format.Positioning + from := xlsxFrom{} + from.Col = colStart + from.ColOff = formatSet.Format.OffsetX * EMU + from.Row = rowStart + from.RowOff = formatSet.Format.OffsetY * EMU + to := xlsxTo{} + to.Col = colEnd + to.ColOff = x2 * EMU + to.Row = rowEnd + to.RowOff = y2 * EMU + twoCellAnchor.From = &from + twoCellAnchor.To = &to + shape := xdrSp{ + NvSpPr: &xdrNvSpPr{ + CNvPr: &xlsxCNvPr{ + ID: cNvPrID, + Name: "Shape " + strconv.Itoa(cNvPrID), + }, + CNvSpPr: &xdrCNvSpPr{ + TxBox: true, + }, + }, + SpPr: &xlsxSpPr{ + PrstGeom: xlsxPrstGeom{ + Prst: formatSet.Type, + }, + }, + Style: &xdrStyle{ + LnRef: setShapeRef(formatSet.Color.Line, 2), + FillRef: setShapeRef(formatSet.Color.Fill, 1), + EffectRef: setShapeRef(formatSet.Color.Effect, 0), + FontRef: &aFontRef{ + Idx: "minor", + SchemeClr: &attrValString{ + Val: "tx1", + }, + }, + }, + TxBody: &xdrTxBody{ + BodyPr: &aBodyPr{ + VertOverflow: "clip", + HorzOverflow: "clip", + Wrap: "none", + RtlCol: false, + Anchor: "t", + }, + }, + } + if len(formatSet.Paragraph) < 1 { + formatSet.Paragraph = []formatShapeParagraph{ + { + Font: formatFont{ + Bold: false, + Italic: false, + Underline: "none", + Family: "Calibri", + Size: 11, + Color: "#000000", + }, + Text: " ", + }, + } + } + for _, p := range formatSet.Paragraph { + u := p.Font.Underline + _, ok := textUnderlineType[u] + if !ok { + u = "none" + } + text := p.Text + if text == "" { + text = " " + } + paragraph := &aP{ + R: &aR{ + RPr: aRPr{ + I: p.Font.Italic, + B: p.Font.Bold, + Lang: "en-US", + AltLang: "en-US", + U: u, + Sz: p.Font.Size * 100, + Latin: &aLatin{Typeface: p.Font.Family}, + SolidFill: &aSolidFill{ + SrgbClr: &attrValString{ + Val: strings.Replace(strings.ToUpper(p.Font.Color), "#", "", -1), + }, + }, + }, + T: text, + }, + EndParaRPr: &aEndParaRPr{ + Lang: "en-US", + }, + } + shape.TxBody.P = append(shape.TxBody.P, paragraph) + } + twoCellAnchor.Sp = &shape + twoCellAnchor.ClientData = &xdrClientData{ + FLocksWithSheet: formatSet.Format.FLocksWithSheet, + FPrintsWithSheet: formatSet.Format.FPrintsWithSheet, + } + content.TwoCellAnchor = append(content.TwoCellAnchor, &twoCellAnchor) + output, _ := xml.Marshal(content) + f.saveFileList(drawingXML, output) +} + +// setShapeRef provides a function to set color with hex model by given actual +// color value. +func setShapeRef(color string, i int) *aRef { + if color == "" { + return &aRef{ + Idx: 0, + ScrgbClr: &aScrgbClr{ + R: 0, + G: 0, + B: 0, + }, + } + } + return &aRef{ + Idx: i, + SrgbClr: &attrValString{ + Val: strings.Replace(strings.ToUpper(color), "#", "", -1), + }, + } +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/sheet.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/sheet.go new file mode 100644 index 0000000000..b03492c89b --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/sheet.go @@ -0,0 +1,792 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. + +package excelize + +import ( + "bytes" + "encoding/json" + "encoding/xml" + "errors" + "fmt" + "io/ioutil" + "os" + "path" + "regexp" + "strconv" + "strings" + "unicode/utf8" + + "github.com/mohae/deepcopy" +) + +// NewSheet provides function to create a new sheet by given worksheet name. +// When creating a new XLSX file, the default sheet will be created. Returns +// the number of sheets in the workbook (file) after appending the new sheet. +func (f *File) NewSheet(name string) int { + // Check if the worksheet already exists + if f.GetSheetIndex(name) != 0 { + return f.SheetCount + } + f.DeleteSheet(name) + f.SheetCount++ + wb := f.workbookReader() + sheetID := 0 + for _, v := range wb.Sheets.Sheet { + if v.SheetID > sheetID { + sheetID = v.SheetID + } + } + sheetID++ + // Update docProps/app.xml + f.setAppXML() + // Update [Content_Types].xml + f.setContentTypes(sheetID) + // Create new sheet /xl/worksheets/sheet%d.xml + f.setSheet(sheetID, name) + // Update xl/_rels/workbook.xml.rels + rID := f.addXlsxWorkbookRels(sheetID) + // Update xl/workbook.xml + f.setWorkbook(name, sheetID, rID) + return sheetID +} + +// contentTypesReader provides a function to get the pointer to the +// [Content_Types].xml structure after deserialization. +func (f *File) contentTypesReader() *xlsxTypes { + if f.ContentTypes == nil { + var content xlsxTypes + _ = xml.Unmarshal(namespaceStrictToTransitional(f.readXML("[Content_Types].xml")), &content) + f.ContentTypes = &content + } + return f.ContentTypes +} + +// contentTypesWriter provides a function to save [Content_Types].xml after +// serialize structure. +func (f *File) contentTypesWriter() { + if f.ContentTypes != nil { + output, _ := xml.Marshal(f.ContentTypes) + f.saveFileList("[Content_Types].xml", output) + } +} + +// workbookReader provides a function to get the pointer to the xl/workbook.xml +// structure after deserialization. +func (f *File) workbookReader() *xlsxWorkbook { + if f.WorkBook == nil { + var content xlsxWorkbook + _ = xml.Unmarshal(namespaceStrictToTransitional(f.readXML("xl/workbook.xml")), &content) + f.WorkBook = &content + } + return f.WorkBook +} + +// workbookWriter provides a function to save xl/workbook.xml after serialize +// structure. +func (f *File) workbookWriter() { + if f.WorkBook != nil { + output, _ := xml.Marshal(f.WorkBook) + f.saveFileList("xl/workbook.xml", replaceRelationshipsNameSpaceBytes(output)) + } +} + +// worksheetWriter provides a function to save xl/worksheets/sheet%d.xml after +// serialize structure. +func (f *File) worksheetWriter() { + for path, sheet := range f.Sheet { + if sheet != nil { + for k, v := range sheet.SheetData.Row { + f.Sheet[path].SheetData.Row[k].C = trimCell(v.C) + } + output, _ := xml.Marshal(sheet) + f.saveFileList(path, replaceWorkSheetsRelationshipsNameSpaceBytes(output)) + ok := f.checked[path] + if ok { + f.checked[path] = false + } + } + } +} + +// trimCell provides a function to trim blank cells which created by completeCol. +func trimCell(column []xlsxC) []xlsxC { + col := make([]xlsxC, len(column)) + i := 0 + for _, c := range column { + if c.S != 0 || c.V != "" || c.F != nil || c.T != "" { + col[i] = c + i++ + } + } + return col[0:i] +} + +// setContentTypes provides a function to read and update property of contents +// type of XLSX. +func (f *File) setContentTypes(index int) { + content := f.contentTypesReader() + content.Overrides = append(content.Overrides, xlsxOverride{ + PartName: "/xl/worksheets/sheet" + strconv.Itoa(index) + ".xml", + ContentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml", + }) +} + +// setSheet provides a function to update sheet property by given index. +func (f *File) setSheet(index int, name string) { + var xlsx xlsxWorksheet + xlsx.Dimension.Ref = "A1" + xlsx.SheetViews.SheetView = append(xlsx.SheetViews.SheetView, xlsxSheetView{ + WorkbookViewID: 0, + }) + path := "xl/worksheets/sheet" + strconv.Itoa(index) + ".xml" + f.sheetMap[trimSheetName(name)] = path + f.Sheet[path] = &xlsx +} + +// setWorkbook update workbook property of XLSX. Maximum 31 characters are +// allowed in sheet title. +func (f *File) setWorkbook(name string, sheetID, rid int) { + content := f.workbookReader() + content.Sheets.Sheet = append(content.Sheets.Sheet, xlsxSheet{ + Name: trimSheetName(name), + SheetID: sheetID, + ID: "rId" + strconv.Itoa(rid), + }) +} + +// workbookRelsReader provides a function to read and unmarshal workbook +// relationships of XLSX file. +func (f *File) workbookRelsReader() *xlsxWorkbookRels { + if f.WorkBookRels == nil { + var content xlsxWorkbookRels + _ = xml.Unmarshal(namespaceStrictToTransitional(f.readXML("xl/_rels/workbook.xml.rels")), &content) + f.WorkBookRels = &content + } + return f.WorkBookRels +} + +// workbookRelsWriter provides a function to save xl/_rels/workbook.xml.rels after +// serialize structure. +func (f *File) workbookRelsWriter() { + if f.WorkBookRels != nil { + output, _ := xml.Marshal(f.WorkBookRels) + f.saveFileList("xl/_rels/workbook.xml.rels", output) + } +} + +// addXlsxWorkbookRels update workbook relationships property of XLSX. +func (f *File) addXlsxWorkbookRels(sheet int) int { + content := f.workbookRelsReader() + rID := 0 + for _, v := range content.Relationships { + t, _ := strconv.Atoi(strings.TrimPrefix(v.ID, "rId")) + if t > rID { + rID = t + } + } + rID++ + ID := bytes.Buffer{} + ID.WriteString("rId") + ID.WriteString(strconv.Itoa(rID)) + target := bytes.Buffer{} + target.WriteString("worksheets/sheet") + target.WriteString(strconv.Itoa(sheet)) + target.WriteString(".xml") + content.Relationships = append(content.Relationships, xlsxWorkbookRelation{ + ID: ID.String(), + Target: target.String(), + Type: SourceRelationshipWorkSheet, + }) + return rID +} + +// setAppXML update docProps/app.xml file of XML. +func (f *File) setAppXML() { + f.saveFileList("docProps/app.xml", []byte(templateDocpropsApp)) +} + +// replaceRelationshipsNameSpaceBytes; Some tools that read XLSX files have +// very strict requirements about the structure of the input XML. In +// particular both Numbers on the Mac and SAS dislike inline XML namespace +// declarations, or namespace prefixes that don't match the ones that Excel +// itself uses. This is a problem because the Go XML library doesn't multiple +// namespace declarations in a single element of a document. This function is +// a horrible hack to fix that after the XML marshalling is completed. +func replaceRelationshipsNameSpaceBytes(workbookMarshal []byte) []byte { + oldXmlns := []byte(``) + newXmlns := []byte(``) + return bytes.Replace(workbookMarshal, oldXmlns, newXmlns, -1) +} + +// SetActiveSheet provides function to set default active worksheet of XLSX by +// given index. Note that active index is different from the index returned by +// function GetSheetMap(). It should be greater than 0 and less than total +// worksheet numbers. +func (f *File) SetActiveSheet(index int) { + if index < 1 { + index = 1 + } + wb := f.workbookReader() + for activeTab, sheet := range wb.Sheets.Sheet { + if sheet.SheetID == index { + if len(wb.BookViews.WorkBookView) > 0 { + wb.BookViews.WorkBookView[0].ActiveTab = activeTab + } else { + wb.BookViews.WorkBookView = append(wb.BookViews.WorkBookView, xlsxWorkBookView{ + ActiveTab: activeTab, + }) + } + } + } + for idx, name := range f.GetSheetMap() { + xlsx := f.workSheetReader(name) + if len(xlsx.SheetViews.SheetView) > 0 { + xlsx.SheetViews.SheetView[0].TabSelected = false + } + if index == idx { + if len(xlsx.SheetViews.SheetView) > 0 { + xlsx.SheetViews.SheetView[0].TabSelected = true + } else { + xlsx.SheetViews.SheetView = append(xlsx.SheetViews.SheetView, xlsxSheetView{ + TabSelected: true, + }) + } + } + } +} + +// GetActiveSheetIndex provides a function to get active sheet index of the +// XLSX. If not found the active sheet will be return integer 0. +func (f *File) GetActiveSheetIndex() int { + for idx, name := range f.GetSheetMap() { + xlsx := f.workSheetReader(name) + for _, sheetView := range xlsx.SheetViews.SheetView { + if sheetView.TabSelected { + return idx + } + } + } + return 0 +} + +// SetSheetName provides a function to set the worksheet name be given old and new +// worksheet name. Maximum 31 characters are allowed in sheet title and this +// function only changes the name of the sheet and will not update the sheet +// name in the formula or reference associated with the cell. So there may be +// problem formula error or reference missing. +func (f *File) SetSheetName(oldName, newName string) { + oldName = trimSheetName(oldName) + newName = trimSheetName(newName) + content := f.workbookReader() + for k, v := range content.Sheets.Sheet { + if v.Name == oldName { + content.Sheets.Sheet[k].Name = newName + f.sheetMap[newName] = f.sheetMap[oldName] + delete(f.sheetMap, oldName) + } + } +} + +// GetSheetName provides a function to get worksheet name of XLSX by given +// worksheet index. If given sheet index is invalid, will return an empty +// string. +func (f *File) GetSheetName(index int) string { + content := f.workbookReader() + rels := f.workbookRelsReader() + for _, rel := range rels.Relationships { + rID, _ := strconv.Atoi(strings.TrimSuffix(strings.TrimPrefix(rel.Target, "worksheets/sheet"), ".xml")) + if rID == index { + for _, v := range content.Sheets.Sheet { + if v.ID == rel.ID { + return v.Name + } + } + } + } + return "" +} + +// GetSheetIndex provides a function to get worksheet index of XLSX by given sheet +// name. If given worksheet name is invalid, will return an integer type value +// 0. +func (f *File) GetSheetIndex(name string) int { + content := f.workbookReader() + rels := f.workbookRelsReader() + for _, v := range content.Sheets.Sheet { + if v.Name == name { + for _, rel := range rels.Relationships { + if v.ID == rel.ID { + rID, _ := strconv.Atoi(strings.TrimSuffix(strings.TrimPrefix(rel.Target, "worksheets/sheet"), ".xml")) + return rID + } + } + } + } + return 0 +} + +// GetSheetMap provides a function to get worksheet name and index map of XLSX. +// For example: +// +// xlsx, err := excelize.OpenFile("./Book1.xlsx") +// if err != nil { +// return +// } +// for index, name := range xlsx.GetSheetMap() { +// fmt.Println(index, name) +// } +// +func (f *File) GetSheetMap() map[int]string { + content := f.workbookReader() + rels := f.workbookRelsReader() + sheetMap := map[int]string{} + for _, v := range content.Sheets.Sheet { + for _, rel := range rels.Relationships { + relStr := strings.SplitN(rel.Target, "worksheets/sheet", 2) + if rel.ID == v.ID && len(relStr) == 2 { + rID, _ := strconv.Atoi(strings.TrimSuffix(relStr[1], ".xml")) + sheetMap[rID] = v.Name + } + } + } + return sheetMap +} + +// getSheetMap provides a function to get worksheet name and XML file path map of +// XLSX. +func (f *File) getSheetMap() map[string]string { + maps := make(map[string]string) + for idx, name := range f.GetSheetMap() { + maps[name] = "xl/worksheets/sheet" + strconv.Itoa(idx) + ".xml" + } + return maps +} + +// SetSheetBackground provides a function to set background picture by given +// worksheet name and file path. +func (f *File) SetSheetBackground(sheet, picture string) error { + var err error + // Check picture exists first. + if _, err = os.Stat(picture); os.IsNotExist(err) { + return err + } + ext, ok := supportImageTypes[path.Ext(picture)] + if !ok { + return errors.New("unsupported image extension") + } + pictureID := f.countMedia() + 1 + rID := f.addSheetRelationships(sheet, SourceRelationshipImage, "../media/image"+strconv.Itoa(pictureID)+ext, "") + f.addSheetPicture(sheet, rID) + file, _ := ioutil.ReadFile(picture) + f.addMedia(file, ext) + f.setContentTypePartImageExtensions() + return err +} + +// DeleteSheet provides a function to delete worksheet in a workbook by given +// worksheet name. Use this method with caution, which will affect changes in +// references such as formulas, charts, and so on. If there is any referenced +// value of the deleted worksheet, it will cause a file error when you open it. +// This function will be invalid when only the one worksheet is left. +func (f *File) DeleteSheet(name string) { + content := f.workbookReader() + for k, v := range content.Sheets.Sheet { + if v.Name == trimSheetName(name) && len(content.Sheets.Sheet) > 1 { + content.Sheets.Sheet = append(content.Sheets.Sheet[:k], content.Sheets.Sheet[k+1:]...) + sheet := "xl/worksheets/sheet" + strconv.Itoa(v.SheetID) + ".xml" + rels := "xl/worksheets/_rels/sheet" + strconv.Itoa(v.SheetID) + ".xml.rels" + target := f.deleteSheetFromWorkbookRels(v.ID) + f.deleteSheetFromContentTypes(target) + delete(f.sheetMap, name) + delete(f.XLSX, sheet) + delete(f.XLSX, rels) + delete(f.Sheet, sheet) + f.SheetCount-- + } + } + f.SetActiveSheet(len(f.GetSheetMap())) +} + +// deleteSheetFromWorkbookRels provides a function to remove worksheet +// relationships by given relationships ID in the file +// xl/_rels/workbook.xml.rels. +func (f *File) deleteSheetFromWorkbookRels(rID string) string { + content := f.workbookRelsReader() + for k, v := range content.Relationships { + if v.ID == rID { + content.Relationships = append(content.Relationships[:k], content.Relationships[k+1:]...) + return v.Target + } + } + return "" +} + +// deleteSheetFromContentTypes provides a function to remove worksheet +// relationships by given target name in the file [Content_Types].xml. +func (f *File) deleteSheetFromContentTypes(target string) { + content := f.contentTypesReader() + for k, v := range content.Overrides { + if v.PartName == "/xl/"+target { + content.Overrides = append(content.Overrides[:k], content.Overrides[k+1:]...) + } + } +} + +// CopySheet provides a function to duplicate a worksheet by gave source and +// target worksheet index. Note that currently doesn't support duplicate +// workbooks that contain tables, charts or pictures. For Example: +// +// // Sheet1 already exists... +// index := xlsx.NewSheet("Sheet2") +// err := xlsx.CopySheet(1, index) +// return err +// +func (f *File) CopySheet(from, to int) error { + if from < 1 || to < 1 || from == to || f.GetSheetName(from) == "" || f.GetSheetName(to) == "" { + return errors.New("invalid worksheet index") + } + f.copySheet(from, to) + return nil +} + +// copySheet provides a function to duplicate a worksheet by gave source and +// target worksheet name. +func (f *File) copySheet(from, to int) { + sheet := f.workSheetReader("sheet" + strconv.Itoa(from)) + worksheet := deepcopy.Copy(sheet).(*xlsxWorksheet) + path := "xl/worksheets/sheet" + strconv.Itoa(to) + ".xml" + if len(worksheet.SheetViews.SheetView) > 0 { + worksheet.SheetViews.SheetView[0].TabSelected = false + } + worksheet.Drawing = nil + worksheet.TableParts = nil + worksheet.PageSetUp = nil + f.Sheet[path] = worksheet + toRels := "xl/worksheets/_rels/sheet" + strconv.Itoa(to) + ".xml.rels" + fromRels := "xl/worksheets/_rels/sheet" + strconv.Itoa(from) + ".xml.rels" + _, ok := f.XLSX[fromRels] + if ok { + f.XLSX[toRels] = f.XLSX[fromRels] + } +} + +// SetSheetVisible provides a function to set worksheet visible by given worksheet +// name. A workbook must contain at least one visible worksheet. If the given +// worksheet has been activated, this setting will be invalidated. Sheet state +// values as defined by http://msdn.microsoft.com/en-us/library/office/documentformat.openxml.spreadsheet.sheetstatevalues.aspx +// +// visible +// hidden +// veryHidden +// +// For example, hide Sheet1: +// +// xlsx.SetSheetVisible("Sheet1", false) +// +func (f *File) SetSheetVisible(name string, visible bool) { + name = trimSheetName(name) + content := f.workbookReader() + if visible { + for k, v := range content.Sheets.Sheet { + if v.Name == name { + content.Sheets.Sheet[k].State = "" + } + } + return + } + count := 0 + for _, v := range content.Sheets.Sheet { + if v.State != "hidden" { + count++ + } + } + for k, v := range content.Sheets.Sheet { + xlsx := f.workSheetReader(f.GetSheetMap()[k]) + tabSelected := false + if len(xlsx.SheetViews.SheetView) > 0 { + tabSelected = xlsx.SheetViews.SheetView[0].TabSelected + } + if v.Name == name && count > 1 && !tabSelected { + content.Sheets.Sheet[k].State = "hidden" + } + } +} + +// parseFormatPanesSet provides a function to parse the panes settings. +func parseFormatPanesSet(formatSet string) (*formatPanes, error) { + format := formatPanes{} + err := json.Unmarshal([]byte(formatSet), &format) + return &format, err +} + +// SetPanes provides a function to create and remove freeze panes and split panes +// by given worksheet name and panes format set. +// +// activePane defines the pane that is active. The possible values for this +// attribute are defined in the following table: +// +// Enumeration Value | Description +// --------------------------------+------------------------------------------------------------- +// bottomLeft (Bottom Left Pane) | Bottom left pane, when both vertical and horizontal +// | splits are applied. +// | +// | This value is also used when only a horizontal split has +// | been applied, dividing the pane into upper and lower +// | regions. In that case, this value specifies the bottom +// | pane. +// | +// bottomRight (Bottom Right Pane) | Bottom right pane, when both vertical and horizontal +// | splits are applied. +// | +// topLeft (Top Left Pane) | Top left pane, when both vertical and horizontal splits +// | are applied. +// | +// | This value is also used when only a horizontal split has +// | been applied, dividing the pane into upper and lower +// | regions. In that case, this value specifies the top pane. +// | +// | This value is also used when only a vertical split has +// | been applied, dividing the pane into right and left +// | regions. In that case, this value specifies the left pane +// | +// topRight (Top Right Pane) | Top right pane, when both vertical and horizontal +// | splits are applied. +// | +// | This value is also used when only a vertical split has +// | been applied, dividing the pane into right and left +// | regions. In that case, this value specifies the right +// | pane. +// +// Pane state type is restricted to the values supported currently listed in the following table: +// +// Enumeration Value | Description +// --------------------------------+------------------------------------------------------------- +// frozen (Frozen) | Panes are frozen, but were not split being frozen. In +// | this state, when the panes are unfrozen again, a single +// | pane results, with no split. +// | +// | In this state, the split bars are not adjustable. +// | +// split (Split) | Panes are split, but not frozen. In this state, the split +// | bars are adjustable by the user. +// +// x_split (Horizontal Split Position): Horizontal position of the split, in +// 1/20th of a point; 0 (zero) if none. If the pane is frozen, this value +// indicates the number of columns visible in the top pane. +// +// y_split (Vertical Split Position): Vertical position of the split, in 1/20th +// of a point; 0 (zero) if none. If the pane is frozen, this value indicates the +// number of rows visible in the left pane. The possible values for this +// attribute are defined by the W3C XML Schema double datatype. +// +// top_left_cell: Location of the top left visible cell in the bottom right pane +// (when in Left-To-Right mode). +// +// sqref (Sequence of References): Range of the selection. Can be non-contiguous +// set of ranges. +// +// An example of how to freeze column A in the Sheet1 and set the active cell on +// Sheet1!K16: +// +// xlsx.SetPanes("Sheet1", `{"freeze":true,"split":false,"x_split":1,"y_split":0,"top_left_cell":"B1","active_pane":"topRight","panes":[{"sqref":"K16","active_cell":"K16","pane":"topRight"}]}`) +// +// An example of how to freeze rows 1 to 9 in the Sheet1 and set the active cell +// ranges on Sheet1!A11:XFD11: +// +// xlsx.SetPanes("Sheet1", `{"freeze":true,"split":false,"x_split":0,"y_split":9,"top_left_cell":"A34","active_pane":"bottomLeft","panes":[{"sqref":"A11:XFD11","active_cell":"A11","pane":"bottomLeft"}]}`) +// +// An example of how to create split panes in the Sheet1 and set the active cell +// on Sheet1!J60: +// +// xlsx.SetPanes("Sheet1", `{"freeze":false,"split":true,"x_split":3270,"y_split":1800,"top_left_cell":"N57","active_pane":"bottomLeft","panes":[{"sqref":"I36","active_cell":"I36"},{"sqref":"G33","active_cell":"G33","pane":"topRight"},{"sqref":"J60","active_cell":"J60","pane":"bottomLeft"},{"sqref":"O60","active_cell":"O60","pane":"bottomRight"}]}`) +// +// An example of how to unfreeze and remove all panes on Sheet1: +// +// xlsx.SetPanes("Sheet1", `{"freeze":false,"split":false}`) +// +func (f *File) SetPanes(sheet, panes string) { + fs, _ := parseFormatPanesSet(panes) + xlsx := f.workSheetReader(sheet) + p := &xlsxPane{ + ActivePane: fs.ActivePane, + TopLeftCell: fs.TopLeftCell, + XSplit: float64(fs.XSplit), + YSplit: float64(fs.YSplit), + } + if fs.Freeze { + p.State = "frozen" + } + xlsx.SheetViews.SheetView[len(xlsx.SheetViews.SheetView)-1].Pane = p + if !(fs.Freeze) && !(fs.Split) { + if len(xlsx.SheetViews.SheetView) > 0 { + xlsx.SheetViews.SheetView[len(xlsx.SheetViews.SheetView)-1].Pane = nil + } + } + s := []*xlsxSelection{} + for _, p := range fs.Panes { + s = append(s, &xlsxSelection{ + ActiveCell: p.ActiveCell, + Pane: p.Pane, + SQRef: p.SQRef, + }) + } + xlsx.SheetViews.SheetView[len(xlsx.SheetViews.SheetView)-1].Selection = s +} + +// GetSheetVisible provides a function to get worksheet visible by given worksheet +// name. For example, get visible state of Sheet1: +// +// xlsx.GetSheetVisible("Sheet1") +// +func (f *File) GetSheetVisible(name string) bool { + content := f.workbookReader() + visible := false + for k, v := range content.Sheets.Sheet { + if v.Name == trimSheetName(name) { + if content.Sheets.Sheet[k].State == "" || content.Sheets.Sheet[k].State == "visible" { + visible = true + } + } + } + return visible +} + +// SearchSheet provides a function to get coordinates by given worksheet name, +// cell value, and regular expression. The function doesn't support searching +// on the calculated result, formatted numbers and conditional lookup +// currently. If it is a merged cell, it will return the coordinates of the +// upper left corner of the merged area. +// +// An example of search the coordinates of the value of "100" on Sheet1: +// +// xlsx.SearchSheet("Sheet1", "100") +// +// An example of search the coordinates where the numerical value in the range +// of "0-9" of Sheet1 is described: +// +// xlsx.SearchSheet("Sheet1", "[0-9]", true) +// +func (f *File) SearchSheet(sheet, value string, reg ...bool) []string { + var regSearch bool + for _, r := range reg { + regSearch = r + } + xlsx := f.workSheetReader(sheet) + result := []string{} + name, ok := f.sheetMap[trimSheetName(sheet)] + if !ok { + return result + } + if xlsx != nil { + output, _ := xml.Marshal(f.Sheet[name]) + f.saveFileList(name, replaceWorkSheetsRelationshipsNameSpaceBytes(output)) + } + xml.NewDecoder(bytes.NewReader(f.readXML(name))) + d := f.sharedStringsReader() + var inElement string + var r xlsxRow + decoder := xml.NewDecoder(bytes.NewReader(f.readXML(name))) + for { + token, _ := decoder.Token() + if token == nil { + break + } + switch startElement := token.(type) { + case xml.StartElement: + inElement = startElement.Name.Local + if inElement == "row" { + r = xlsxRow{} + _ = decoder.DecodeElement(&r, &startElement) + for _, colCell := range r.C { + val, _ := colCell.getValueFrom(f, d) + if regSearch { + regex := regexp.MustCompile(value) + if !regex.MatchString(val) { + continue + } + } else { + if val != value { + continue + } + } + result = append(result, fmt.Sprintf("%s%d", strings.Map(letterOnlyMapF, colCell.R), r.R)) + } + } + default: + } + } + return result +} + +// ProtectSheet provides a function to prevent other users from accidentally +// or deliberately changing, moving, or deleting data in a worksheet. For +// example, protect Sheet1 with protection settings: +// +// xlsx.ProtectSheet("Sheet1", &excelize.FormatSheetProtection{ +// Password: "password", +// EditScenarios: false, +// }) +// +func (f *File) ProtectSheet(sheet string, settings *FormatSheetProtection) { + xlsx := f.workSheetReader(sheet) + if settings == nil { + settings = &FormatSheetProtection{ + EditObjects: true, + EditScenarios: true, + SelectLockedCells: true, + } + } + xlsx.SheetProtection = &xlsxSheetProtection{ + AutoFilter: settings.AutoFilter, + DeleteColumns: settings.DeleteColumns, + DeleteRows: settings.DeleteRows, + FormatCells: settings.FormatCells, + FormatColumns: settings.FormatColumns, + FormatRows: settings.FormatRows, + InsertColumns: settings.InsertColumns, + InsertHyperlinks: settings.InsertHyperlinks, + InsertRows: settings.InsertRows, + Objects: settings.EditObjects, + PivotTables: settings.PivotTables, + Scenarios: settings.EditScenarios, + SelectLockedCells: settings.SelectLockedCells, + SelectUnlockedCells: settings.SelectUnlockedCells, + Sheet: true, + Sort: settings.Sort, + } + if settings.Password != "" { + xlsx.SheetProtection.Password = genSheetPasswd(settings.Password) + } +} + +// UnprotectSheet provides a function to unprotect an Excel worksheet. +func (f *File) UnprotectSheet(sheet string) { + xlsx := f.workSheetReader(sheet) + xlsx.SheetProtection = nil +} + +// trimSheetName provides a function to trim invaild characters by given worksheet +// name. +func trimSheetName(name string) string { + r := []rune{} + for _, v := range name { + switch v { + case 58, 92, 47, 63, 42, 91, 93: // replace :\/?*[] + continue + default: + r = append(r, v) + } + } + name = string(r) + if utf8.RuneCountInString(name) > 31 { + name = string([]rune(name)[0:31]) + } + return name +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/sheetpr.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/sheetpr.go new file mode 100644 index 0000000000..4497e7a837 --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/sheetpr.go @@ -0,0 +1,168 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. + +package excelize + +// SheetPrOption is an option of a view of a worksheet. See SetSheetPrOptions(). +type SheetPrOption interface { + setSheetPrOption(view *xlsxSheetPr) +} + +// SheetPrOptionPtr is a writable SheetPrOption. See GetSheetPrOptions(). +type SheetPrOptionPtr interface { + SheetPrOption + getSheetPrOption(view *xlsxSheetPr) +} + +type ( + // CodeName is a SheetPrOption + CodeName string + // EnableFormatConditionsCalculation is a SheetPrOption + EnableFormatConditionsCalculation bool + // Published is a SheetPrOption + Published bool + // FitToPage is a SheetPrOption + FitToPage bool + // AutoPageBreaks is a SheetPrOption + AutoPageBreaks bool + // OutlineSummaryBelow is an outlinePr, within SheetPr option + OutlineSummaryBelow bool +) + +func (o OutlineSummaryBelow) setSheetPrOption(pr *xlsxSheetPr) { + if pr.OutlinePr == nil { + pr.OutlinePr = new(xlsxOutlinePr) + } + pr.OutlinePr.SummaryBelow = bool(o) +} + +func (o *OutlineSummaryBelow) getSheetPrOption(pr *xlsxSheetPr) { + // Excel default: true + if pr == nil || pr.OutlinePr == nil { + *o = true + return + } + *o = OutlineSummaryBelow(defaultTrue(&pr.OutlinePr.SummaryBelow)) +} + +func (o CodeName) setSheetPrOption(pr *xlsxSheetPr) { + pr.CodeName = string(o) +} + +func (o *CodeName) getSheetPrOption(pr *xlsxSheetPr) { + if pr == nil { + *o = "" + return + } + *o = CodeName(pr.CodeName) +} + +func (o EnableFormatConditionsCalculation) setSheetPrOption(pr *xlsxSheetPr) { + pr.EnableFormatConditionsCalculation = boolPtr(bool(o)) +} + +func (o *EnableFormatConditionsCalculation) getSheetPrOption(pr *xlsxSheetPr) { + if pr == nil { + *o = true + return + } + *o = EnableFormatConditionsCalculation(defaultTrue(pr.EnableFormatConditionsCalculation)) +} + +func (o Published) setSheetPrOption(pr *xlsxSheetPr) { + pr.Published = boolPtr(bool(o)) +} + +func (o *Published) getSheetPrOption(pr *xlsxSheetPr) { + if pr == nil { + *o = true + return + } + *o = Published(defaultTrue(pr.Published)) +} + +func (o FitToPage) setSheetPrOption(pr *xlsxSheetPr) { + if pr.PageSetUpPr == nil { + if !o { + return + } + pr.PageSetUpPr = new(xlsxPageSetUpPr) + } + pr.PageSetUpPr.FitToPage = bool(o) +} + +func (o *FitToPage) getSheetPrOption(pr *xlsxSheetPr) { + // Excel default: false + if pr == nil || pr.PageSetUpPr == nil { + *o = false + return + } + *o = FitToPage(pr.PageSetUpPr.FitToPage) +} + +func (o AutoPageBreaks) setSheetPrOption(pr *xlsxSheetPr) { + if pr.PageSetUpPr == nil { + if !o { + return + } + pr.PageSetUpPr = new(xlsxPageSetUpPr) + } + pr.PageSetUpPr.AutoPageBreaks = bool(o) +} + +func (o *AutoPageBreaks) getSheetPrOption(pr *xlsxSheetPr) { + // Excel default: false + if pr == nil || pr.PageSetUpPr == nil { + *o = false + return + } + *o = AutoPageBreaks(pr.PageSetUpPr.AutoPageBreaks) +} + +// SetSheetPrOptions provides a function to sets worksheet properties. +// +// Available options: +// CodeName(string) +// EnableFormatConditionsCalculation(bool) +// Published(bool) +// FitToPage(bool) +// AutoPageBreaks(bool) +// OutlineSummaryBelow(bool) +func (f *File) SetSheetPrOptions(name string, opts ...SheetPrOption) error { + sheet := f.workSheetReader(name) + pr := sheet.SheetPr + if pr == nil { + pr = new(xlsxSheetPr) + sheet.SheetPr = pr + } + + for _, opt := range opts { + opt.setSheetPrOption(pr) + } + return nil +} + +// GetSheetPrOptions provides a function to gets worksheet properties. +// +// Available options: +// CodeName(string) +// EnableFormatConditionsCalculation(bool) +// Published(bool) +// FitToPage(bool) +// AutoPageBreaks(bool) +// OutlineSummaryBelow(bool) +func (f *File) GetSheetPrOptions(name string, opts ...SheetPrOptionPtr) error { + sheet := f.workSheetReader(name) + pr := sheet.SheetPr + + for _, opt := range opts { + opt.getSheetPrOption(pr) + } + return nil +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/sheetview.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/sheetview.go new file mode 100644 index 0000000000..6b191e92f5 --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/sheetview.go @@ -0,0 +1,171 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. + +package excelize + +import "fmt" + +// SheetViewOption is an option of a view of a worksheet. See SetSheetViewOptions(). +type SheetViewOption interface { + setSheetViewOption(view *xlsxSheetView) +} + +// SheetViewOptionPtr is a writable SheetViewOption. See GetSheetViewOptions(). +type SheetViewOptionPtr interface { + SheetViewOption + getSheetViewOption(view *xlsxSheetView) +} + +type ( + // DefaultGridColor is a SheetViewOption. + DefaultGridColor bool + // RightToLeft is a SheetViewOption. + RightToLeft bool + // ShowFormulas is a SheetViewOption. + ShowFormulas bool + // ShowGridLines is a SheetViewOption. + ShowGridLines bool + // ShowRowColHeaders is a SheetViewOption. + ShowRowColHeaders bool + // ZoomScale is a SheetViewOption. + ZoomScale float64 + // TopLeftCell is a SheetViewOption. + TopLeftCell string + /* TODO + // ShowWhiteSpace is a SheetViewOption. + ShowWhiteSpace bool + // ShowZeros is a SheetViewOption. + ShowZeros bool + // WindowProtection is a SheetViewOption. + WindowProtection bool + */ +) + +// Defaults for each option are described in XML schema for CT_SheetView + +func (o TopLeftCell) setSheetViewOption(view *xlsxSheetView) { + view.TopLeftCell = string(o) +} + +func (o *TopLeftCell) getSheetViewOption(view *xlsxSheetView) { + *o = TopLeftCell(string(view.TopLeftCell)) +} + +func (o DefaultGridColor) setSheetViewOption(view *xlsxSheetView) { + view.DefaultGridColor = boolPtr(bool(o)) +} + +func (o *DefaultGridColor) getSheetViewOption(view *xlsxSheetView) { + *o = DefaultGridColor(defaultTrue(view.DefaultGridColor)) // Excel default: true +} + +func (o RightToLeft) setSheetViewOption(view *xlsxSheetView) { + view.RightToLeft = bool(o) // Excel default: false +} + +func (o *RightToLeft) getSheetViewOption(view *xlsxSheetView) { + *o = RightToLeft(view.RightToLeft) +} + +func (o ShowFormulas) setSheetViewOption(view *xlsxSheetView) { + view.ShowFormulas = bool(o) // Excel default: false +} + +func (o *ShowFormulas) getSheetViewOption(view *xlsxSheetView) { + *o = ShowFormulas(view.ShowFormulas) // Excel default: false +} + +func (o ShowGridLines) setSheetViewOption(view *xlsxSheetView) { + view.ShowGridLines = boolPtr(bool(o)) +} + +func (o *ShowGridLines) getSheetViewOption(view *xlsxSheetView) { + *o = ShowGridLines(defaultTrue(view.ShowGridLines)) // Excel default: true +} + +func (o ShowRowColHeaders) setSheetViewOption(view *xlsxSheetView) { + view.ShowRowColHeaders = boolPtr(bool(o)) +} + +func (o *ShowRowColHeaders) getSheetViewOption(view *xlsxSheetView) { + *o = ShowRowColHeaders(defaultTrue(view.ShowRowColHeaders)) // Excel default: true +} + +func (o ZoomScale) setSheetViewOption(view *xlsxSheetView) { + //This attribute is restricted to values ranging from 10 to 400. + if float64(o) >= 10 && float64(o) <= 400 { + view.ZoomScale = float64(o) + } +} + +func (o *ZoomScale) getSheetViewOption(view *xlsxSheetView) { + *o = ZoomScale(view.ZoomScale) +} + +// getSheetView returns the SheetView object +func (f *File) getSheetView(sheetName string, viewIndex int) (*xlsxSheetView, error) { + xlsx := f.workSheetReader(sheetName) + if viewIndex < 0 { + if viewIndex < -len(xlsx.SheetViews.SheetView) { + return nil, fmt.Errorf("view index %d out of range", viewIndex) + } + viewIndex = len(xlsx.SheetViews.SheetView) + viewIndex + } else if viewIndex >= len(xlsx.SheetViews.SheetView) { + return nil, fmt.Errorf("view index %d out of range", viewIndex) + } + + return &(xlsx.SheetViews.SheetView[viewIndex]), nil +} + +// SetSheetViewOptions sets sheet view options. +// The viewIndex may be negative and if so is counted backward (-1 is the last view). +// +// Available options: +// DefaultGridColor(bool) +// RightToLeft(bool) +// ShowFormulas(bool) +// ShowGridLines(bool) +// ShowRowColHeaders(bool) +// Example: +// err = f.SetSheetViewOptions("Sheet1", -1, ShowGridLines(false)) +func (f *File) SetSheetViewOptions(name string, viewIndex int, opts ...SheetViewOption) error { + view, err := f.getSheetView(name, viewIndex) + if err != nil { + return err + } + + for _, opt := range opts { + opt.setSheetViewOption(view) + } + return nil +} + +// GetSheetViewOptions gets the value of sheet view options. +// The viewIndex may be negative and if so is counted backward (-1 is the last view). +// +// Available options: +// DefaultGridColor(bool) +// RightToLeft(bool) +// ShowFormulas(bool) +// ShowGridLines(bool) +// ShowRowColHeaders(bool) +// Example: +// var showGridLines excelize.ShowGridLines +// err = f.GetSheetViewOptions("Sheet1", -1, &showGridLines) +func (f *File) GetSheetViewOptions(name string, viewIndex int, opts ...SheetViewOptionPtr) error { + view, err := f.getSheetView(name, viewIndex) + if err != nil { + return err + } + + for _, opt := range opts { + opt.getSheetViewOption(view) + } + return nil +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/styles.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/styles.go new file mode 100644 index 0000000000..d075266693 --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/styles.go @@ -0,0 +1,2780 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. + +package excelize + +import ( + "encoding/json" + "encoding/xml" + "fmt" + "math" + "strconv" + "strings" +) + +// Excel styles can reference number formats that are built-in, all of which +// have an id less than 164. This is a possibly incomplete list comprised of +// as many of them as I could find. +var builtInNumFmt = map[int]string{ + 0: "general", + 1: "0", + 2: "0.00", + 3: "#,##0", + 4: "#,##0.00", + 9: "0%", + 10: "0.00%", + 11: "0.00e+00", + 12: "# ?/?", + 13: "# ??/??", + 14: "mm-dd-yy", + 15: "d-mmm-yy", + 16: "d-mmm", + 17: "mmm-yy", + 18: "h:mm am/pm", + 19: "h:mm:ss am/pm", + 20: "h:mm", + 21: "h:mm:ss", + 22: "m/d/yy h:mm", + 37: "#,##0 ;(#,##0)", + 38: "#,##0 ;[red](#,##0)", + 39: "#,##0.00;(#,##0.00)", + 40: "#,##0.00;[red](#,##0.00)", + 41: `_(* #,##0_);_(* \(#,##0\);_(* "-"_);_(@_)`, + 42: `_("$"* #,##0_);_("$* \(#,##0\);_("$"* "-"_);_(@_)`, + 43: `_(* #,##0.00_);_(* \(#,##0.00\);_(* "-"??_);_(@_)`, + 44: `_("$"* #,##0.00_);_("$"* \(#,##0.00\);_("$"* "-"??_);_(@_)`, + 45: "mm:ss", + 46: "[h]:mm:ss", + 47: "mmss.0", + 48: "##0.0e+0", + 49: "@", +} + +// langNumFmt defined number format code (with unicode values provided for +// language glyphs where they occur) in different language. +var langNumFmt = map[string]map[int]string{ + "zh-tw": { + 27: "[$-404]e/m/d", + 28: `[$-404]e"年"m"月"d"日"`, + 29: `[$-404]e"年"m"月"d"日"`, + 30: "m/d/yy", + 31: `yyyy"年"m"月"d"日"`, + 32: `hh"時"mm"分"`, + 33: `hh"時"mm"分"ss"秒"`, + 34: `上午/下午 hh"時"mm"分"`, + 35: `上午/下午 hh"時"mm"分"ss"秒"`, + 36: "[$-404]e/m/d", + 50: "[$-404]e/m/d", + 51: `[$-404]e"年"m"月"d"日"`, + 52: `上午/下午 hh"時"mm"分"`, + 53: `上午/下午 hh"時"mm"分"ss"秒"`, + 54: `[$-404]e"年"m"月"d"日"`, + 55: `上午/下午 hh"時"mm"分"`, + 56: `上午/下午 hh"時"mm"分"ss"秒"`, + 57: "[$-404]e/m/d", + 58: `[$-404]e"年"m"月"d"日"`, + }, + "zh-cn": { + 27: `yyyy"年"m"月"`, + 28: `m"月"d"日"`, + 29: `m"月"d"日"`, + 30: "m-d-yy", + 31: `yyyy"年"m"月"d"日"`, + 32: `h"时"mm"分"`, + 33: `h"时"mm"分"ss"秒"`, + 34: `上午/下午 h"时"mm"分"`, + 35: `上午/下午 h"时"mm"分"ss"秒"`, + 36: `yyyy"年"m"月"`, + 50: `yyyy"年"m"月"`, + 51: `m"月"d"日"`, + 52: `yyyy"年"m"月"`, + 53: `m"月"d"日"`, + 54: `m"月"d"日"`, + 55: `上午/下午 h"时"mm"分"`, + 56: `上午/下午 h"时"mm"分"ss"秒"`, + 57: `yyyy"年"m"月"`, + 58: `m"月"d"日"`, + }, + "zh-tw_unicode": { + 27: "[$-404]e/m/d", + 28: `[$-404]e"5E74"m"6708"d"65E5"`, + 29: `[$-404]e"5E74"m"6708"d"65E5"`, + 30: "m/d/yy", + 31: `yyyy"5E74"m"6708"d"65E5"`, + 32: `hh"6642"mm"5206"`, + 33: `hh"6642"mm"5206"ss"79D2"`, + 34: `4E0A5348/4E0B5348hh"6642"mm"5206"`, + 35: `4E0A5348/4E0B5348hh"6642"mm"5206"ss"79D2"`, + 36: "[$-404]e/m/d", + 50: "[$-404]e/m/d", + 51: `[$-404]e"5E74"m"6708"d"65E5"`, + 52: `4E0A5348/4E0B5348hh"6642"mm"5206"`, + 53: `4E0A5348/4E0B5348hh"6642"mm"5206"ss"79D2"`, + 54: `[$-404]e"5E74"m"6708"d"65E5"`, + 55: `4E0A5348/4E0B5348hh"6642"mm"5206"`, + 56: `4E0A5348/4E0B5348hh"6642"mm"5206"ss"79D2"`, + 57: "[$-404]e/m/d", + 58: `[$-404]e"5E74"m"6708"d"65E5"`, + }, + "zh-cn_unicode": { + 27: `yyyy"5E74"m"6708"`, + 28: `m"6708"d"65E5"`, + 29: `m"6708"d"65E5"`, + 30: "m-d-yy", + 31: `yyyy"5E74"m"6708"d"65E5"`, + 32: `h"65F6"mm"5206"`, + 33: `h"65F6"mm"5206"ss"79D2"`, + 34: `4E0A5348/4E0B5348h"65F6"mm"5206"`, + 35: `4E0A5348/4E0B5348h"65F6"mm"5206"ss"79D2"`, + 36: `yyyy"5E74"m"6708"`, + 50: `yyyy"5E74"m"6708"`, + 51: `m"6708"d"65E5"`, + 52: `yyyy"5E74"m"6708"`, + 53: `m"6708"d"65E5"`, + 54: `m"6708"d"65E5"`, + 55: `4E0A5348/4E0B5348h"65F6"mm"5206"`, + 56: `4E0A5348/4E0B5348h"65F6"mm"5206"ss"79D2"`, + 57: `yyyy"5E74"m"6708"`, + 58: `m"6708"d"65E5"`, + }, + "ja-jp": { + 27: "[$-411]ge.m.d", + 28: `[$-411]ggge"年"m"月"d"日"`, + 29: `[$-411]ggge"年"m"月"d"日"`, + 30: "m/d/yy", + 31: `yyyy"年"m"月"d"日"`, + 32: `h"時"mm"分"`, + 33: `h"時"mm"分"ss"秒"`, + 34: `yyyy"年"m"月"`, + 35: `m"月"d"日"`, + 36: "[$-411]ge.m.d", + 50: "[$-411]ge.m.d", + 51: `[$-411]ggge"年"m"月"d"日"`, + 52: `yyyy"年"m"月"`, + 53: `m"月"d"日"`, + 54: `[$-411]ggge"年"m"月"d"日"`, + 55: `yyyy"年"m"月"`, + 56: `m"月"d"日"`, + 57: "[$-411]ge.m.d", + 58: `[$-411]ggge"年"m"月"d"日"`, + }, + "ko-kr": { + 27: `yyyy"年" mm"月" dd"日"`, + 28: "mm-dd", + 29: "mm-dd", + 30: "mm-dd-yy", + 31: `yyyy"년" mm"월" dd"일"`, + 32: `h"시" mm"분"`, + 33: `h"시" mm"분" ss"초"`, + 34: `yyyy-mm-dd`, + 35: `yyyy-mm-dd`, + 36: `yyyy"年" mm"月" dd"日"`, + 50: `yyyy"年" mm"月" dd"日"`, + 51: "mm-dd", + 52: "yyyy-mm-dd", + 53: "yyyy-mm-dd", + 54: "mm-dd", + 55: "yyyy-mm-dd", + 56: "yyyy-mm-dd", + 57: `yyyy"年" mm"月" dd"日"`, + 58: "mm-dd", + }, + "ja-jp_unicode": { + 27: "[$-411]ge.m.d", + 28: `[$-411]ggge"5E74"m"6708"d"65E5"`, + 29: `[$-411]ggge"5E74"m"6708"d"65E5"`, + 30: "m/d/yy", + 31: `yyyy"5E74"m"6708"d"65E5"`, + 32: `h"6642"mm"5206"`, + 33: `h"6642"mm"5206"ss"79D2"`, + 34: `yyyy"5E74"m"6708"`, + 35: `m"6708"d"65E5"`, + 36: "[$-411]ge.m.d", + 50: "[$-411]ge.m.d", + 51: `[$-411]ggge"5E74"m"6708"d"65E5"`, + 52: `yyyy"5E74"m"6708"`, + 53: `m"6708"d"65E5"`, + 54: `[$-411]ggge"5E74"m"6708"d"65E5"`, + 55: `yyyy"5E74"m"6708"`, + 56: `m"6708"d"65E5"`, + 57: "[$-411]ge.m.d", + 58: `[$-411]ggge"5E74"m"6708"d"65E5"`, + }, + "ko-kr_unicode": { + 27: `yyyy"5E74" mm"6708" dd"65E5"`, + 28: "mm-dd", + 29: "mm-dd", + 30: "mm-dd-yy", + 31: `yyyy"B144" mm"C6D4" dd"C77C"`, + 32: `h"C2DC" mm"BD84"`, + 33: `h"C2DC" mm"BD84" ss"CD08"`, + 34: "yyyy-mm-dd", + 35: "yyyy-mm-dd", + 36: `yyyy"5E74" mm"6708" dd"65E5"`, + 50: `yyyy"5E74" mm"6708" dd"65E5"`, + 51: "mm-dd", + 52: "yyyy-mm-dd", + 53: "yyyy-mm-dd", + 54: "mm-dd", + 55: "yyyy-mm-dd", + 56: "yyyy-mm-dd", + 57: `yyyy"5E74" mm"6708" dd"65E5"`, + 58: "mm-dd", + }, + "th-th": { + 59: "t0", + 60: "t0.00", + 61: "t#,##0", + 62: "t#,##0.00", + 67: "t0%", + 68: "t0.00%", + 69: "t# ?/?", + 70: "t# ??/??", + 71: "ว/ด/ปปปป", + 72: "ว-ดดด-ปป", + 73: "ว-ดดด", + 74: "ดดด-ปป", + 75: "ช:นน", + 76: "ช:นน:ทท", + 77: "ว/ด/ปปปป ช:นน", + 78: "นน:ทท", + 79: "[ช]:นน:ทท", + 80: "นน:ทท.0", + 81: "d/m/bb", + }, + "th-th_unicode": { + 59: "t0", + 60: "t0.00", + 61: "t#,##0", + 62: "t#,##0.00", + 67: "t0%", + 68: "t0.00%", + 69: "t# ?/?", + 70: "t# ??/??", + 71: "0E27/0E14/0E1B0E1B0E1B0E1B", + 72: "0E27-0E140E140E14-0E1B0E1B", + 73: "0E27-0E140E140E14", + 74: "0E140E140E14-0E1B0E1B", + 75: "0E0A:0E190E19", + 76: "0E0A:0E190E19:0E170E17", + 77: "0E27/0E14/0E1B0E1B0E1B0E1B 0E0A:0E190E19", + 78: "0E190E19:0E170E17", + 79: "[0E0A]:0E190E19:0E170E17", + 80: "0E190E19:0E170E17.0", + 81: "d/m/bb", + }, +} + +// currencyNumFmt defined the currency number format map. +var currencyNumFmt = map[int]string{ + 164: `"CN¥",##0.00`, + 165: "[$$-409]#,##0.00", + 166: "[$$-45C]#,##0.00", + 167: "[$$-1004]#,##0.00", + 168: "[$$-404]#,##0.00", + 169: "[$$-C09]#,##0.00", + 170: "[$$-2809]#,##0.00", + 171: "[$$-1009]#,##0.00", + 172: "[$$-2009]#,##0.00", + 173: "[$$-1409]#,##0.00", + 174: "[$$-4809]#,##0.00", + 175: "[$$-2C09]#,##0.00", + 176: "[$$-2409]#,##0.00", + 177: "[$$-1000]#,##0.00", + 178: `#,##0.00\ [$$-C0C]`, + 179: "[$$-475]#,##0.00", + 180: "[$$-83E]#,##0.00", + 181: `[$$-86B]\ #,##0.00`, + 182: `[$$-340A]\ #,##0.00`, + 183: "[$$-240A]#,##0.00", + 184: `[$$-300A]\ #,##0.00`, + 185: "[$$-440A]#,##0.00", + 186: "[$$-80A]#,##0.00", + 187: "[$$-500A]#,##0.00", + 188: "[$$-540A]#,##0.00", + 189: `[$$-380A]\ #,##0.00`, + 190: "[$£-809]#,##0.00", + 191: "[$£-491]#,##0.00", + 192: "[$£-452]#,##0.00", + 193: "[$¥-804]#,##0.00", + 194: "[$¥-411]#,##0.00", + 195: "[$¥-478]#,##0.00", + 196: "[$¥-451]#,##0.00", + 197: "[$¥-480]#,##0.00", + 198: "#,##0.00\\ [$\u058F-42B]", + 199: "[$\u060B-463]#,##0.00", + 200: "[$\u060B-48C]#,##0.00", + 201: "[$\u09F3-845]\\ #,##0.00", + 202: "#,##0.00[$\u17DB-453]", + 203: "[$\u20A1-140A]#,##0.00", + 204: "[$\u20A6-468]\\ #,##0.00", + 205: "[$\u20A6-470]\\ #,##0.00", + 206: "[$\u20A9-412]#,##0.00", + 207: "[$\u20AA-40D]\\ #,##0.00", + 208: "#,##0.00\\ [$\u20AB-42A]", + 209: "#,##0.00\\ [$\u20AC-42D]", + 210: "#,##0.00\\ [$\u20AC-47E]", + 211: "#,##0.00\\ [$\u20AC-403]", + 212: "#,##0.00\\ [$\u20AC-483]", + 213: "[$\u20AC-813]\\ #,##0.00", + 214: "[$\u20AC-413]\\ #,##0.00", + 215: "[$\u20AC-1809]#,##0.00", + 216: "#,##0.00\\ [$\u20AC-425]", + 217: "[$\u20AC-2]\\ #,##0.00", + 218: "#,##0.00\\ [$\u20AC-1]", + 219: "#,##0.00\\ [$\u20AC-40B]", + 220: "#,##0.00\\ [$\u20AC-80C]", + 221: "#,##0.00\\ [$\u20AC-40C]", + 222: "#,##0.00\\ [$\u20AC-140C]", + 223: "#,##0.00\\ [$\u20AC-180C]", + 224: "[$\u20AC-200C]#,##0.00", + 225: "#,##0.00\\ [$\u20AC-456]", + 226: "#,##0.00\\ [$\u20AC-C07]", + 227: "#,##0.00\\ [$\u20AC-407]", + 228: "#,##0.00\\ [$\u20AC-1007]", + 229: "#,##0.00\\ [$\u20AC-408]", + 230: "#,##0.00\\ [$\u20AC-243B]", + 231: "[$\u20AC-83C]#,##0.00", + 232: "[$\u20AC-410]\\ #,##0.00", + 233: "[$\u20AC-476]#,##0.00", + 234: "#,##0.00\\ [$\u20AC-2C1A]", + 235: "[$\u20AC-426]\\ #,##0.00", + 236: "#,##0.00\\ [$\u20AC-427]", + 237: "#,##0.00\\ [$\u20AC-82E]", + 238: "#,##0.00\\ [$\u20AC-46E]", + 239: "[$\u20AC-43A]#,##0.00", + 240: "#,##0.00\\ [$\u20AC-C3B]", + 241: "#,##0.00\\ [$\u20AC-482]", + 242: "#,##0.00\\ [$\u20AC-816]", + 243: "#,##0.00\\ [$\u20AC-301A]", + 244: "#,##0.00\\ [$\u20AC-203B]", + 245: "#,##0.00\\ [$\u20AC-41B]", + 246: "#,##0.00\\ [$\u20AC-424]", + 247: "#,##0.00\\ [$\u20AC-C0A]", + 248: "#,##0.00\\ [$\u20AC-81D]", + 249: "#,##0.00\\ [$\u20AC-484]", + 250: "#,##0.00\\ [$\u20AC-42E]", + 251: "[$\u20AC-462]\\ #,##0.00", + 252: "#,##0.00\\ [$₭-454]", + 253: "#,##0.00\\ [$₮-450]", + 254: "[$\u20AE-C50]#,##0.00", + 255: "[$\u20B1-3409]#,##0.00", + 256: "[$\u20B1-464]#,##0.00", + 257: "#,##0.00[$\u20B4-422]", + 258: "[$\u20B8-43F]#,##0.00", + 259: "[$\u20B9-460]#,##0.00", + 260: "[$\u20B9-4009]\\ #,##0.00", + 261: "[$\u20B9-447]\\ #,##0.00", + 262: "[$\u20B9-439]\\ #,##0.00", + 263: "[$\u20B9-44B]\\ #,##0.00", + 264: "[$\u20B9-860]#,##0.00", + 265: "[$\u20B9-457]\\ #,##0.00", + 266: "[$\u20B9-458]#,##0.00", + 267: "[$\u20B9-44E]\\ #,##0.00", + 268: "[$\u20B9-861]#,##0.00", + 269: "[$\u20B9-448]\\ #,##0.00", + 270: "[$\u20B9-446]\\ #,##0.00", + 271: "[$\u20B9-44F]\\ #,##0.00", + 272: "[$\u20B9-459]#,##0.00", + 273: "[$\u20B9-449]\\ #,##0.00", + 274: "[$\u20B9-820]#,##0.00", + 275: "#,##0.00\\ [$\u20BA-41F]", + 276: "#,##0.00\\ [$\u20BC-42C]", + 277: "#,##0.00\\ [$\u20BC-82C]", + 278: "#,##0.00\\ [$\u20BD-419]", + 279: "#,##0.00[$\u20BD-485]", + 280: "#,##0.00\\ [$\u20BE-437]", + 281: "[$B/.-180A]\\ #,##0.00", + 282: "[$Br-472]#,##0.00", + 283: "[$Br-477]#,##0.00", + 284: "#,##0.00[$Br-473]", + 285: "[$Bs-46B]\\ #,##0.00", + 286: "[$Bs-400A]\\ #,##0.00", + 287: "[$Bs.-200A]\\ #,##0.00", + 288: "[$BWP-832]\\ #,##0.00", + 289: "[$C$-4C0A]#,##0.00", + 290: "[$CA$-85D]#,##0.00", + 291: "[$CA$-47C]#,##0.00", + 292: "[$CA$-45D]#,##0.00", + 293: "[$CFA-340C]#,##0.00", + 294: "[$CFA-280C]#,##0.00", + 295: "#,##0.00\\ [$CFA-867]", + 296: "#,##0.00\\ [$CFA-488]", + 297: "#,##0.00\\ [$CHF-100C]", + 298: "[$CHF-1407]\\ #,##0.00", + 299: "[$CHF-807]\\ #,##0.00", + 300: "[$CHF-810]\\ #,##0.00", + 301: "[$CHF-417]\\ #,##0.00", + 302: "[$CLP-47A]\\ #,##0.00", + 303: "[$CN¥-850]#,##0.00", + 304: "#,##0.00\\ [$DZD-85F]", + 305: "[$FCFA-2C0C]#,##0.00", + 306: "#,##0.00\\ [$Ft-40E]", + 307: "[$G-3C0C]#,##0.00", + 308: "[$Gs.-3C0A]\\ #,##0.00", + 309: "[$GTQ-486]#,##0.00", + 310: "[$HK$-C04]#,##0.00", + 311: "[$HK$-3C09]#,##0.00", + 312: "#,##0.00\\ [$HRK-41A]", + 313: "[$IDR-3809]#,##0.00", + 314: "[$IQD-492]#,##0.00", + 315: "#,##0.00\\ [$ISK-40F]", + 316: "[$K-455]#,##0.00", + 317: "#,##0.00\\ [$K\u010D-405]", + 318: "#,##0.00\\ [$KM-141A]", + 319: "#,##0.00\\ [$KM-101A]", + 320: "#,##0.00\\ [$KM-181A]", + 321: "[$kr-438]\\ #,##0.00", + 322: "[$kr-43B]\\ #,##0.00", + 323: "#,##0.00\\ [$kr-83B]", + 324: "[$kr-414]\\ #,##0.00", + 325: "[$kr-814]\\ #,##0.00", + 326: "#,##0.00\\ [$kr-41D]", + 327: "[$kr.-406]\\ #,##0.00", + 328: "[$kr.-46F]\\ #,##0.00", + 329: "[$Ksh-441]#,##0.00", + 330: "[$L-818]#,##0.00", + 331: "[$L-819]#,##0.00", + 332: "[$L-480A]\\ #,##0.00", + 333: "#,##0.00\\ [$Lek\u00EB-41C]", + 334: "[$MAD-45F]#,##0.00", + 335: "[$MAD-380C]#,##0.00", + 336: "#,##0.00\\ [$MAD-105F]", + 337: "[$MOP$-1404]#,##0.00", + 338: "#,##0.00\\ [$MVR-465]_-", + 339: "#,##0.00[$Nfk-873]", + 340: "[$NGN-466]#,##0.00", + 341: "[$NGN-467]#,##0.00", + 342: "[$NGN-469]#,##0.00", + 343: "[$NGN-471]#,##0.00", + 344: "[$NOK-103B]\\ #,##0.00", + 345: "[$NOK-183B]\\ #,##0.00", + 346: "[$NZ$-481]#,##0.00", + 347: "[$PKR-859]\\ #,##0.00", + 348: "[$PYG-474]#,##0.00", + 349: "[$Q-100A]#,##0.00", + 350: "[$R-436]\\ #,##0.00", + 351: "[$R-1C09]\\ #,##0.00", + 352: "[$R-435]\\ #,##0.00", + 353: "[$R$-416]\\ #,##0.00", + 354: "[$RD$-1C0A]#,##0.00", + 355: "#,##0.00\\ [$RF-487]", + 356: "[$RM-4409]#,##0.00", + 357: "[$RM-43E]#,##0.00", + 358: "#,##0.00\\ [$RON-418]", + 359: "[$Rp-421]#,##0.00", + 360: "[$Rs-420]#,##0.00_-", + 361: "[$Rs.-849]\\ #,##0.00", + 362: "#,##0.00\\ [$RSD-81A]", + 363: "#,##0.00\\ [$RSD-C1A]", + 364: "#,##0.00\\ [$RUB-46D]", + 365: "#,##0.00\\ [$RUB-444]", + 366: "[$S/.-C6B]\\ #,##0.00", + 367: "[$S/.-280A]\\ #,##0.00", + 368: "#,##0.00\\ [$SEK-143B]", + 369: "#,##0.00\\ [$SEK-1C3B]", + 370: "#,##0.00\\ [$so\u02BBm-443]", + 371: "#,##0.00\\ [$so\u02BBm-843]", + 372: "#,##0.00\\ [$SYP-45A]", + 373: "[$THB-41E]#,##0.00", + 374: "#,##0.00[$TMT-442]", + 375: "[$US$-3009]#,##0.00", + 376: "[$ZAR-46C]\\ #,##0.00", + 377: "[$ZAR-430]#,##0.00", + 378: "[$ZAR-431]#,##0.00", + 379: "[$ZAR-432]\\ #,##0.00", + 380: "[$ZAR-433]#,##0.00", + 381: "[$ZAR-434]\\ #,##0.00", + 382: "#,##0.00\\ [$z\u0142-415]", + 383: "#,##0.00\\ [$\u0434\u0435\u043D-42F]", + 384: "#,##0.00\\ [$КМ-201A]", + 385: "#,##0.00\\ [$КМ-1C1A]", + 386: "#,##0.00\\ [$\u043B\u0432.-402]", + 387: "#,##0.00\\ [$р.-423]", + 388: "#,##0.00\\ [$\u0441\u043E\u043C-440]", + 389: "#,##0.00\\ [$\u0441\u043E\u043C-428]", + 390: "[$\u062C.\u0645.-C01]\\ #,##0.00_-", + 391: "[$\u062F.\u0623.-2C01]\\ #,##0.00_-", + 392: "[$\u062F.\u0625.-3801]\\ #,##0.00_-", + 393: "[$\u062F.\u0628.-3C01]\\ #,##0.00_-", + 394: "[$\u062F.\u062A.-1C01]\\ #,##0.00_-", + 395: "[$\u062F.\u062C.-1401]\\ #,##0.00_-", + 396: "[$\u062F.\u0639.-801]\\ #,##0.00_-", + 397: "[$\u062F.\u0643.-3401]\\ #,##0.00_-", + 398: "[$\u062F.\u0644.-1001]#,##0.00_-", + 399: "[$\u062F.\u0645.-1801]\\ #,##0.00_-", + 400: "[$\u0631-846]\\ #,##0.00", + 401: "[$\u0631.\u0633.-401]\\ #,##0.00_-", + 402: "[$\u0631.\u0639.-2001]\\ #,##0.00_-", + 403: "[$\u0631.\u0642.-4001]\\ #,##0.00_-", + 404: "[$\u0631.\u064A.-2401]\\ #,##0.00_-", + 405: "[$\u0631\u06CC\u0627\u0644-429]#,##0.00_-", + 406: "[$\u0644.\u0633.-2801]\\ #,##0.00_-", + 407: "[$\u0644.\u0644.-3001]\\ #,##0.00_-", + 408: "[$\u1265\u122D-45E]#,##0.00", + 409: "[$\u0930\u0942-461]#,##0.00", + 410: "[$\u0DBB\u0DD4.-45B]\\ #,##0.00", + 411: "[$ADP]\\ #,##0.00", + 412: "[$AED]\\ #,##0.00", + 413: "[$AFA]\\ #,##0.00", + 414: "[$AFN]\\ #,##0.00", + 415: "[$ALL]\\ #,##0.00", + 416: "[$AMD]\\ #,##0.00", + 417: "[$ANG]\\ #,##0.00", + 418: "[$AOA]\\ #,##0.00", + 419: "[$ARS]\\ #,##0.00", + 420: "[$ATS]\\ #,##0.00", + 421: "[$AUD]\\ #,##0.00", + 422: "[$AWG]\\ #,##0.00", + 423: "[$AZM]\\ #,##0.00", + 424: "[$AZN]\\ #,##0.00", + 425: "[$BAM]\\ #,##0.00", + 426: "[$BBD]\\ #,##0.00", + 427: "[$BDT]\\ #,##0.00", + 428: "[$BEF]\\ #,##0.00", + 429: "[$BGL]\\ #,##0.00", + 430: "[$BGN]\\ #,##0.00", + 431: "[$BHD]\\ #,##0.00", + 432: "[$BIF]\\ #,##0.00", + 433: "[$BMD]\\ #,##0.00", + 434: "[$BND]\\ #,##0.00", + 435: "[$BOB]\\ #,##0.00", + 436: "[$BOV]\\ #,##0.00", + 437: "[$BRL]\\ #,##0.00", + 438: "[$BSD]\\ #,##0.00", + 439: "[$BTN]\\ #,##0.00", + 440: "[$BWP]\\ #,##0.00", + 441: "[$BYR]\\ #,##0.00", + 442: "[$BZD]\\ #,##0.00", + 443: "[$CAD]\\ #,##0.00", + 444: "[$CDF]\\ #,##0.00", + 445: "[$CHE]\\ #,##0.00", + 446: "[$CHF]\\ #,##0.00", + 447: "[$CHW]\\ #,##0.00", + 448: "[$CLF]\\ #,##0.00", + 449: "[$CLP]\\ #,##0.00", + 450: "[$CNY]\\ #,##0.00", + 451: "[$COP]\\ #,##0.00", + 452: "[$COU]\\ #,##0.00", + 453: "[$CRC]\\ #,##0.00", + 454: "[$CSD]\\ #,##0.00", + 455: "[$CUC]\\ #,##0.00", + 456: "[$CVE]\\ #,##0.00", + 457: "[$CYP]\\ #,##0.00", + 458: "[$CZK]\\ #,##0.00", + 459: "[$DEM]\\ #,##0.00", + 460: "[$DJF]\\ #,##0.00", + 461: "[$DKK]\\ #,##0.00", + 462: "[$DOP]\\ #,##0.00", + 463: "[$DZD]\\ #,##0.00", + 464: "[$ECS]\\ #,##0.00", + 465: "[$ECV]\\ #,##0.00", + 466: "[$EEK]\\ #,##0.00", + 467: "[$EGP]\\ #,##0.00", + 468: "[$ERN]\\ #,##0.00", + 469: "[$ESP]\\ #,##0.00", + 470: "[$ETB]\\ #,##0.00", + 471: "[$EUR]\\ #,##0.00", + 472: "[$FIM]\\ #,##0.00", + 473: "[$FJD]\\ #,##0.00", + 474: "[$FKP]\\ #,##0.00", + 475: "[$FRF]\\ #,##0.00", + 476: "[$GBP]\\ #,##0.00", + 477: "[$GEL]\\ #,##0.00", + 478: "[$GHC]\\ #,##0.00", + 479: "[$GHS]\\ #,##0.00", + 480: "[$GIP]\\ #,##0.00", + 481: "[$GMD]\\ #,##0.00", + 482: "[$GNF]\\ #,##0.00", + 483: "[$GRD]\\ #,##0.00", + 484: "[$GTQ]\\ #,##0.00", + 485: "[$GYD]\\ #,##0.00", + 486: "[$HKD]\\ #,##0.00", + 487: "[$HNL]\\ #,##0.00", + 488: "[$HRK]\\ #,##0.00", + 489: "[$HTG]\\ #,##0.00", + 490: "[$HUF]\\ #,##0.00", + 491: "[$IDR]\\ #,##0.00", + 492: "[$IEP]\\ #,##0.00", + 493: "[$ILS]\\ #,##0.00", + 494: "[$INR]\\ #,##0.00", + 495: "[$IQD]\\ #,##0.00", + 496: "[$IRR]\\ #,##0.00", + 497: "[$ISK]\\ #,##0.00", + 498: "[$ITL]\\ #,##0.00", + 499: "[$JMD]\\ #,##0.00", + 500: "[$JOD]\\ #,##0.00", + 501: "[$JPY]\\ #,##0.00", + 502: "[$KAF]\\ #,##0.00", + 503: "[$KES]\\ #,##0.00", + 504: "[$KGS]\\ #,##0.00", + 505: "[$KHR]\\ #,##0.00", + 506: "[$KMF]\\ #,##0.00", + 507: "[$KPW]\\ #,##0.00", + 508: "[$KRW]\\ #,##0.00", + 509: "[$KWD]\\ #,##0.00", + 510: "[$KYD]\\ #,##0.00", + 511: "[$KZT]\\ #,##0.00", + 512: "[$LAK]\\ #,##0.00", + 513: "[$LBP]\\ #,##0.00", + 514: "[$LKR]\\ #,##0.00", + 515: "[$LRD]\\ #,##0.00", + 516: "[$LSL]\\ #,##0.00", + 517: "[$LTL]\\ #,##0.00", + 518: "[$LUF]\\ #,##0.00", + 519: "[$LVL]\\ #,##0.00", + 520: "[$LYD]\\ #,##0.00", + 521: "[$MAD]\\ #,##0.00", + 522: "[$MDL]\\ #,##0.00", + 523: "[$MGA]\\ #,##0.00", + 524: "[$MGF]\\ #,##0.00", + 525: "[$MKD]\\ #,##0.00", + 526: "[$MMK]\\ #,##0.00", + 527: "[$MNT]\\ #,##0.00", + 528: "[$MOP]\\ #,##0.00", + 529: "[$MRO]\\ #,##0.00", + 530: "[$MTL]\\ #,##0.00", + 531: "[$MUR]\\ #,##0.00", + 532: "[$MVR]\\ #,##0.00", + 533: "[$MWK]\\ #,##0.00", + 534: "[$MXN]\\ #,##0.00", + 535: "[$MXV]\\ #,##0.00", + 536: "[$MYR]\\ #,##0.00", + 537: "[$MZM]\\ #,##0.00", + 538: "[$MZN]\\ #,##0.00", + 539: "[$NAD]\\ #,##0.00", + 540: "[$NGN]\\ #,##0.00", + 541: "[$NIO]\\ #,##0.00", + 542: "[$NLG]\\ #,##0.00", + 543: "[$NOK]\\ #,##0.00", + 544: "[$NPR]\\ #,##0.00", + 545: "[$NTD]\\ #,##0.00", + 546: "[$NZD]\\ #,##0.00", + 547: "[$OMR]\\ #,##0.00", + 548: "[$PAB]\\ #,##0.00", + 549: "[$PEN]\\ #,##0.00", + 550: "[$PGK]\\ #,##0.00", + 551: "[$PHP]\\ #,##0.00", + 552: "[$PKR]\\ #,##0.00", + 553: "[$PLN]\\ #,##0.00", + 554: "[$PTE]\\ #,##0.00", + 555: "[$PYG]\\ #,##0.00", + 556: "[$QAR]\\ #,##0.00", + 557: "[$ROL]\\ #,##0.00", + 558: "[$RON]\\ #,##0.00", + 559: "[$RSD]\\ #,##0.00", + 560: "[$RUB]\\ #,##0.00", + 561: "[$RUR]\\ #,##0.00", + 562: "[$RWF]\\ #,##0.00", + 563: "[$SAR]\\ #,##0.00", + 564: "[$SBD]\\ #,##0.00", + 565: "[$SCR]\\ #,##0.00", + 566: "[$SDD]\\ #,##0.00", + 567: "[$SDG]\\ #,##0.00", + 568: "[$SDP]\\ #,##0.00", + 569: "[$SEK]\\ #,##0.00", + 570: "[$SGD]\\ #,##0.00", + 571: "[$SHP]\\ #,##0.00", + 572: "[$SIT]\\ #,##0.00", + 573: "[$SKK]\\ #,##0.00", + 574: "[$SLL]\\ #,##0.00", + 575: "[$SOS]\\ #,##0.00", + 576: "[$SPL]\\ #,##0.00", + 577: "[$SRD]\\ #,##0.00", + 578: "[$SRG]\\ #,##0.00", + 579: "[$STD]\\ #,##0.00", + 580: "[$SVC]\\ #,##0.00", + 581: "[$SYP]\\ #,##0.00", + 582: "[$SZL]\\ #,##0.00", + 583: "[$THB]\\ #,##0.00", + 584: "[$TJR]\\ #,##0.00", + 585: "[$TJS]\\ #,##0.00", + 586: "[$TMM]\\ #,##0.00", + 587: "[$TMT]\\ #,##0.00", + 588: "[$TND]\\ #,##0.00", + 589: "[$TOP]\\ #,##0.00", + 590: "[$TRL]\\ #,##0.00", + 591: "[$TRY]\\ #,##0.00", + 592: "[$TTD]\\ #,##0.00", + 593: "[$TWD]\\ #,##0.00", + 594: "[$TZS]\\ #,##0.00", + 595: "[$UAH]\\ #,##0.00", + 596: "[$UGX]\\ #,##0.00", + 597: "[$USD]\\ #,##0.00", + 598: "[$USN]\\ #,##0.00", + 599: "[$USS]\\ #,##0.00", + 600: "[$UYI]\\ #,##0.00", + 601: "[$UYU]\\ #,##0.00", + 602: "[$UZS]\\ #,##0.00", + 603: "[$VEB]\\ #,##0.00", + 604: "[$VEF]\\ #,##0.00", + 605: "[$VND]\\ #,##0.00", + 606: "[$VUV]\\ #,##0.00", + 607: "[$WST]\\ #,##0.00", + 608: "[$XAF]\\ #,##0.00", + 609: "[$XAG]\\ #,##0.00", + 610: "[$XAU]\\ #,##0.00", + 611: "[$XB5]\\ #,##0.00", + 612: "[$XBA]\\ #,##0.00", + 613: "[$XBB]\\ #,##0.00", + 614: "[$XBC]\\ #,##0.00", + 615: "[$XBD]\\ #,##0.00", + 616: "[$XCD]\\ #,##0.00", + 617: "[$XDR]\\ #,##0.00", + 618: "[$XFO]\\ #,##0.00", + 619: "[$XFU]\\ #,##0.00", + 620: "[$XOF]\\ #,##0.00", + 621: "[$XPD]\\ #,##0.00", + 622: "[$XPF]\\ #,##0.00", + 623: "[$XPT]\\ #,##0.00", + 624: "[$XTS]\\ #,##0.00", + 625: "[$XXX]\\ #,##0.00", + 626: "[$YER]\\ #,##0.00", + 627: "[$YUM]\\ #,##0.00", + 628: "[$ZAR]\\ #,##0.00", + 629: "[$ZMK]\\ #,##0.00", + 630: "[$ZMW]\\ #,##0.00", + 631: "[$ZWD]\\ #,##0.00", + 632: "[$ZWL]\\ #,##0.00", + 633: "[$ZWN]\\ #,##0.00", + 634: "[$ZWR]\\ #,##0.00", +} + +// builtInNumFmtFunc defined the format conversion functions map. Partial format +// code doesn't support currently and will return original string. +var builtInNumFmtFunc = map[int]func(i int, v string) string{ + 0: formatToString, + 1: formatToInt, + 2: formatToFloat, + 3: formatToInt, + 4: formatToFloat, + 9: formatToC, + 10: formatToD, + 11: formatToE, + 12: formatToString, // Doesn't support currently + 13: formatToString, // Doesn't support currently + 14: parseTime, + 15: parseTime, + 16: parseTime, + 17: parseTime, + 18: parseTime, + 19: parseTime, + 20: parseTime, + 21: parseTime, + 22: parseTime, + 37: formatToA, + 38: formatToA, + 39: formatToB, + 40: formatToB, + 41: formatToString, // Doesn't support currently + 42: formatToString, // Doesn't support currently + 43: formatToString, // Doesn't support currently + 44: formatToString, // Doesn't support currently + 45: parseTime, + 46: parseTime, + 47: parseTime, + 48: formatToE, + 49: formatToString, +} + +// validType defined the list of valid validation types. +var validType = map[string]string{ + "cell": "cellIs", + "date": "date", // Doesn't support currently + "time": "time", // Doesn't support currently + "average": "aboveAverage", + "duplicate": "duplicateValues", + "unique": "uniqueValues", + "top": "top10", + "bottom": "top10", + "text": "text", // Doesn't support currently + "time_period": "timePeriod", // Doesn't support currently + "blanks": "containsBlanks", // Doesn't support currently + "no_blanks": "notContainsBlanks", // Doesn't support currently + "errors": "containsErrors", // Doesn't support currently + "no_errors": "notContainsErrors", // Doesn't support currently + "2_color_scale": "2_color_scale", + "3_color_scale": "3_color_scale", + "data_bar": "dataBar", + "formula": "expression", +} + +// criteriaType defined the list of valid criteria types. +var criteriaType = map[string]string{ + "between": "between", + "not between": "notBetween", + "equal to": "equal", + "=": "equal", + "==": "equal", + "not equal to": "notEqual", + "!=": "notEqual", + "<>": "notEqual", + "greater than": "greaterThan", + ">": "greaterThan", + "less than": "lessThan", + "<": "lessThan", + "greater than or equal to": "greaterThanOrEqual", + ">=": "greaterThanOrEqual", + "less than or equal to": "lessThanOrEqual", + "<=": "lessThanOrEqual", + "containing": "containsText", + "not containing": "notContains", + "begins with": "beginsWith", + "ends with": "endsWith", + "yesterday": "yesterday", + "today": "today", + "last 7 days": "last7Days", + "last week": "lastWeek", + "this week": "thisWeek", + "continue week": "continueWeek", + "last month": "lastMonth", + "this month": "thisMonth", + "continue month": "continueMonth", +} + +// formatToString provides a function to return original string by given +// built-in number formats code and cell string. +func formatToString(i int, v string) string { + return v +} + +// formatToInt provides a function to convert original string to integer +// format as string type by given built-in number formats code and cell +// string. +func formatToInt(i int, v string) string { + f, err := strconv.ParseFloat(v, 64) + if err != nil { + return v + } + return fmt.Sprintf("%d", int(f)) +} + +// formatToFloat provides a function to convert original string to float +// format as string type by given built-in number formats code and cell +// string. +func formatToFloat(i int, v string) string { + f, err := strconv.ParseFloat(v, 64) + if err != nil { + return v + } + return fmt.Sprintf("%.2f", f) +} + +// formatToA provides a function to convert original string to special format +// as string type by given built-in number formats code and cell string. +func formatToA(i int, v string) string { + f, err := strconv.ParseFloat(v, 64) + if err != nil { + return v + } + if f < 0 { + t := int(math.Abs(f)) + return fmt.Sprintf("(%d)", t) + } + t := int(f) + return fmt.Sprintf("%d", t) +} + +// formatToB provides a function to convert original string to special format +// as string type by given built-in number formats code and cell string. +func formatToB(i int, v string) string { + f, err := strconv.ParseFloat(v, 64) + if err != nil { + return v + } + if f < 0 { + return fmt.Sprintf("(%.2f)", f) + } + return fmt.Sprintf("%.2f", f) +} + +// formatToC provides a function to convert original string to special format +// as string type by given built-in number formats code and cell string. +func formatToC(i int, v string) string { + f, err := strconv.ParseFloat(v, 64) + if err != nil { + return v + } + f = f * 100 + return fmt.Sprintf("%d%%", int(f)) +} + +// formatToD provides a function to convert original string to special format +// as string type by given built-in number formats code and cell string. +func formatToD(i int, v string) string { + f, err := strconv.ParseFloat(v, 64) + if err != nil { + return v + } + f = f * 100 + return fmt.Sprintf("%.2f%%", f) +} + +// formatToE provides a function to convert original string to special format +// as string type by given built-in number formats code and cell string. +func formatToE(i int, v string) string { + f, err := strconv.ParseFloat(v, 64) + if err != nil { + return v + } + return fmt.Sprintf("%.e", f) +} + +// parseTime provides a function to returns a string parsed using time.Time. +// Replace Excel placeholders with Go time placeholders. For example, replace +// yyyy with 2006. These are in a specific order, due to the fact that m is +// used in month, minute, and am/pm. It would be easier to fix that with +// regular expressions, but if it's possible to keep this simple it would be +// easier to maintain. Full-length month and days (e.g. March, Tuesday) have +// letters in them that would be replaced by other characters below (such as +// the 'h' in March, or the 'd' in Tuesday) below. First we convert them to +// arbitrary characters unused in Excel Date formats, and then at the end, +// turn them to what they should actually be. Based off: +// http://www.ozgrid.com/Excel/CustomFormats.htm +func parseTime(i int, v string) string { + f, err := strconv.ParseFloat(v, 64) + if err != nil { + return v + } + val := timeFromExcelTime(f, false) + format := builtInNumFmt[i] + + replacements := []struct{ xltime, gotime string }{ + {"yyyy", "2006"}, + {"yy", "06"}, + {"mmmm", "%%%%"}, + {"dddd", "&&&&"}, + {"dd", "02"}, + {"d", "2"}, + {"mmm", "Jan"}, + {"mmss", "0405"}, + {"ss", "05"}, + {"mm:", "04:"}, + {":mm", ":04"}, + {"mm", "01"}, + {"am/pm", "pm"}, + {"m/", "1/"}, + {"%%%%", "January"}, + {"&&&&", "Monday"}, + } + // It is the presence of the "am/pm" indicator that determines if this is + // a 12 hour or 24 hours time format, not the number of 'h' characters. + if is12HourTime(format) { + format = strings.Replace(format, "hh", "03", 1) + format = strings.Replace(format, "h", "3", 1) + } else { + format = strings.Replace(format, "hh", "15", 1) + format = strings.Replace(format, "h", "15", 1) + } + for _, repl := range replacements { + format = strings.Replace(format, repl.xltime, repl.gotime, 1) + } + // If the hour is optional, strip it out, along with the possible dangling + // colon that would remain. + if val.Hour() < 1 { + format = strings.Replace(format, "]:", "]", 1) + format = strings.Replace(format, "[03]", "", 1) + format = strings.Replace(format, "[3]", "", 1) + format = strings.Replace(format, "[15]", "", 1) + } else { + format = strings.Replace(format, "[3]", "3", 1) + format = strings.Replace(format, "[15]", "15", 1) + } + return val.Format(format) +} + +// is12HourTime checks whether an Excel time format string is a 12 hours form. +func is12HourTime(format string) bool { + return strings.Contains(format, "am/pm") || strings.Contains(format, "AM/PM") || strings.Contains(format, "a/p") || strings.Contains(format, "A/P") +} + +// stylesReader provides a function to get the pointer to the structure after +// deserialization of xl/styles.xml. +func (f *File) stylesReader() *xlsxStyleSheet { + if f.Styles == nil { + var styleSheet xlsxStyleSheet + _ = xml.Unmarshal(namespaceStrictToTransitional(f.readXML("xl/styles.xml")), &styleSheet) + f.Styles = &styleSheet + } + return f.Styles +} + +// styleSheetWriter provides a function to save xl/styles.xml after serialize +// structure. +func (f *File) styleSheetWriter() { + if f.Styles != nil { + output, _ := xml.Marshal(f.Styles) + f.saveFileList("xl/styles.xml", replaceWorkSheetsRelationshipsNameSpaceBytes(output)) + } +} + +// parseFormatStyleSet provides a function to parse the format settings of the +// cells and conditional formats. +func parseFormatStyleSet(style string) (*formatStyle, error) { + format := formatStyle{ + DecimalPlaces: 2, + } + err := json.Unmarshal([]byte(style), &format) + return &format, err +} + +// NewStyle provides a function to create style for cells by given style +// format. Note that the color field uses RGB color code. +// +// The following shows the border styles sorted by excelize index number: +// +// Index | Name | Weight | Style +// -------+---------------+--------+------------- +// 0 | None | 0 | +// 1 | Continuous | 1 | ----------- +// 2 | Continuous | 2 | ----------- +// 3 | Dash | 1 | - - - - - - +// 4 | Dot | 1 | . . . . . . +// 5 | Continuous | 3 | ----------- +// 6 | Double | 3 | =========== +// 7 | Continuous | 0 | ----------- +// 8 | Dash | 2 | - - - - - - +// 9 | Dash Dot | 1 | - . - . - . +// 10 | Dash Dot | 2 | - . - . - . +// 11 | Dash Dot Dot | 1 | - . . - . . +// 12 | Dash Dot Dot | 2 | - . . - . . +// 13 | SlantDash Dot | 2 | / - . / - . +// +// The following shows the borders in the order shown in the Excel dialog: +// +// Index | Style | Index | Style +// -------+-------------+-------+------------- +// 0 | None | 12 | - . . - . . +// 7 | ----------- | 13 | / - . / - . +// 4 | . . . . . . | 10 | - . - . - . +// 11 | - . . - . . | 8 | - - - - - - +// 9 | - . - . - . | 2 | ----------- +// 3 | - - - - - - | 5 | ----------- +// 1 | ----------- | 6 | =========== +// +// The following shows the shading styles sorted by excelize index number: +// +// Index | Style | Index | Style +// -------+-----------------+-------+----------------- +// 0 | Horizontal | 3 | Diagonal down +// 1 | Vertical | 4 | From corner +// 2 | Diagonal Up | 5 | From center +// +// The following shows the patterns styles sorted by excelize index number: +// +// Index | Style | Index | Style +// -------+-----------------+-------+----------------- +// 0 | None | 10 | darkTrellis +// 1 | solid | 11 | lightHorizontal +// 2 | mediumGray | 12 | lightVertical +// 3 | darkGray | 13 | lightDown +// 4 | lightGray | 14 | lightUp +// 5 | darkHorizontal | 15 | lightGrid +// 6 | darkVertical | 16 | lightTrellis +// 7 | darkDown | 17 | gray125 +// 8 | darkUp | 18 | gray0625 +// 9 | darkGrid | | +// +// The following the type of horizontal alignment in cells: +// +// Style +// ------------------ +// left +// center +// right +// fill +// justify +// centerContinuous +// distributed +// +// The following the type of vertical alignment in cells: +// +// Style +// ------------------ +// top +// center +// justify +// distributed +// +// The following the type of font underline style: +// +// Style +// ------------------ +// single +// double +// +// Excel's built-in all languages formats are shown in the following table: +// +// Index | Format String +// -------+---------------------------------------------------- +// 0 | General +// 1 | 0 +// 2 | 0.00 +// 3 | #,##0 +// 4 | #,##0.00 +// 5 | ($#,##0_);($#,##0) +// 6 | ($#,##0_);[Red]($#,##0) +// 7 | ($#,##0.00_);($#,##0.00) +// 8 | ($#,##0.00_);[Red]($#,##0.00) +// 9 | 0% +// 10 | 0.00% +// 11 | 0.00E+00 +// 12 | # ?/? +// 13 | # ??/?? +// 14 | m/d/yy +// 15 | d-mmm-yy +// 16 | d-mmm +// 17 | mmm-yy +// 18 | h:mm AM/PM +// 19 | h:mm:ss AM/PM +// 20 | h:mm +// 21 | h:mm:ss +// 22 | m/d/yy h:mm +// ... | ... +// 37 | (#,##0_);(#,##0) +// 38 | (#,##0_);[Red](#,##0) +// 39 | (#,##0.00_);(#,##0.00) +// 40 | (#,##0.00_);[Red](#,##0.00) +// 41 | _(* #,##0_);_(* (#,##0);_(* "-"_);_(@_) +// 42 | _($* #,##0_);_($* (#,##0);_($* "-"_);_(@_) +// 43 | _(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_) +// 44 | _($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_) +// 45 | mm:ss +// 46 | [h]:mm:ss +// 47 | mm:ss.0 +// 48 | ##0.0E+0 +// 49 | @ +// +// Number format code in zh-tw language: +// +// Index | Symbol +// -------+------------------------------------------- +// 27 | [$-404]e/m/d +// 28 | [$-404]e"年"m"月"d"日" +// 29 | [$-404]e"年"m"月"d"日" +// 30 | m/d/yy +// 31 | yyyy"年"m"月"d"日" +// 32 | hh"時"mm"分" +// 33 | hh"時"mm"分"ss"秒" +// 34 | 上午/下午 hh"時"mm"分" +// 35 | 上午/下午 hh"時"mm"分"ss"秒" +// 36 | [$-404]e/m/d +// 50 | [$-404]e/m/d +// 51 | [$-404]e"年"m"月"d"日" +// 52 | 上午/下午 hh"時"mm"分" +// 53 | 上午/下午 hh"時"mm"分"ss"秒" +// 54 | [$-404]e"年"m"月"d"日" +// 55 | 上午/下午 hh"時"mm"分" +// 56 | 上午/下午 hh"時"mm"分"ss"秒" +// 57 | [$-404]e/m/d +// 58 | [$-404]e"年"m"月"d"日" +// +// Number format code in zh-cn language: +// +// Index | Symbol +// -------+------------------------------------------- +// 27 | yyyy"年"m"月" +// 28 | m"月"d"日" +// 29 | m"月"d"日" +// 30 | m-d-yy +// 31 | yyyy"年"m"月"d"日" +// 32 | h"时"mm"分" +// 33 | h"时"mm"分"ss"秒" +// 34 | 上午/下午 h"时"mm"分" +// 35 | 上午/下午 h"时"mm"分"ss"秒 +// 36 | yyyy"年"m"月 +// 50 | yyyy"年"m"月 +// 51 | m"月"d"日 +// 52 | yyyy"年"m"月 +// 53 | m"月"d"日 +// 54 | m"月"d"日 +// 55 | 上午/下午 h"时"mm"分 +// 56 | 上午/下午 h"时"mm"分"ss"秒 +// 57 | yyyy"年"m"月 +// 58 | m"月"d"日" +// +// Number format code with unicode values provided for language glyphs where +// they occur in zh-tw language: +// +// Index | Symbol +// -------+------------------------------------------- +// 27 | [$-404]e/m/ +// 28 | [$-404]e"5E74"m"6708"d"65E5 +// 29 | [$-404]e"5E74"m"6708"d"65E5 +// 30 | m/d/y +// 31 | yyyy"5E74"m"6708"d"65E5 +// 32 | hh"6642"mm"5206 +// 33 | hh"6642"mm"5206"ss"79D2 +// 34 | 4E0A5348/4E0B5348hh"6642"mm"5206 +// 35 | 4E0A5348/4E0B5348hh"6642"mm"5206"ss"79D2 +// 36 | [$-404]e/m/ +// 50 | [$-404]e/m/ +// 51 | [$-404]e"5E74"m"6708"d"65E5 +// 52 | 4E0A5348/4E0B5348hh"6642"mm"5206 +// 53 | 4E0A5348/4E0B5348hh"6642"mm"5206"ss"79D2 +// 54 | [$-404]e"5E74"m"6708"d"65E5 +// 55 | 4E0A5348/4E0B5348hh"6642"mm"5206 +// 56 | 4E0A5348/4E0B5348hh"6642"mm"5206"ss"79D2 +// 57 | [$-404]e/m/ +// 58 | [$-404]e"5E74"m"6708"d"65E5" +// +// Number format code with unicode values provided for language glyphs where +// they occur in zh-cn language: +// +// Index | Symbol +// -------+------------------------------------------- +// 27 | yyyy"5E74"m"6708 +// 28 | m"6708"d"65E5 +// 29 | m"6708"d"65E5 +// 30 | m-d-y +// 31 | yyyy"5E74"m"6708"d"65E5 +// 32 | h"65F6"mm"5206 +// 33 | h"65F6"mm"5206"ss"79D2 +// 34 | 4E0A5348/4E0B5348h"65F6"mm"5206 +// 35 | 4E0A5348/4E0B5348h"65F6"mm"5206"ss"79D2 +// 36 | yyyy"5E74"m"6708 +// 50 | yyyy"5E74"m"6708 +// 51 | m"6708"d"65E5 +// 52 | yyyy"5E74"m"6708 +// 53 | m"6708"d"65E5 +// 54 | m"6708"d"65E5 +// 55 | 4E0A5348/4E0B5348h"65F6"mm"5206 +// 56 | 4E0A5348/4E0B5348h"65F6"mm"5206"ss"79D2 +// 57 | yyyy"5E74"m"6708 +// 58 | m"6708"d"65E5" +// +// Number format code in ja-jp language: +// +// Index | Symbol +// -------+------------------------------------------- +// 27 | [$-411]ge.m.d +// 28 | [$-411]ggge"年"m"月"d"日 +// 29 | [$-411]ggge"年"m"月"d"日 +// 30 | m/d/y +// 31 | yyyy"年"m"月"d"日 +// 32 | h"時"mm"分 +// 33 | h"時"mm"分"ss"秒 +// 34 | yyyy"年"m"月 +// 35 | m"月"d"日 +// 36 | [$-411]ge.m.d +// 50 | [$-411]ge.m.d +// 51 | [$-411]ggge"年"m"月"d"日 +// 52 | yyyy"年"m"月 +// 53 | m"月"d"日 +// 54 | [$-411]ggge"年"m"月"d"日 +// 55 | yyyy"年"m"月 +// 56 | m"月"d"日 +// 57 | [$-411]ge.m.d +// 58 | [$-411]ggge"年"m"月"d"日" +// +// Number format code in ko-kr language: +// +// Index | Symbol +// -------+------------------------------------------- +// 27 | yyyy"年" mm"月" dd"日 +// 28 | mm-d +// 29 | mm-d +// 30 | mm-dd-y +// 31 | yyyy"년" mm"월" dd"일 +// 32 | h"시" mm"분 +// 33 | h"시" mm"분" ss"초 +// 34 | yyyy-mm-d +// 35 | yyyy-mm-d +// 36 | yyyy"年" mm"月" dd"日 +// 50 | yyyy"年" mm"月" dd"日 +// 51 | mm-d +// 52 | yyyy-mm-d +// 53 | yyyy-mm-d +// 54 | mm-d +// 55 | yyyy-mm-d +// 56 | yyyy-mm-d +// 57 | yyyy"年" mm"月" dd"日 +// 58 | mm-dd +// +// Number format code with unicode values provided for language glyphs where +// they occur in ja-jp language: +// +// Index | Symbol +// -------+------------------------------------------- +// 27 | [$-411]ge.m.d +// 28 | [$-411]ggge"5E74"m"6708"d"65E5 +// 29 | [$-411]ggge"5E74"m"6708"d"65E5 +// 30 | m/d/y +// 31 | yyyy"5E74"m"6708"d"65E5 +// 32 | h"6642"mm"5206 +// 33 | h"6642"mm"5206"ss"79D2 +// 34 | yyyy"5E74"m"6708 +// 35 | m"6708"d"65E5 +// 36 | [$-411]ge.m.d +// 50 | [$-411]ge.m.d +// 51 | [$-411]ggge"5E74"m"6708"d"65E5 +// 52 | yyyy"5E74"m"6708 +// 53 | m"6708"d"65E5 +// 54 | [$-411]ggge"5E74"m"6708"d"65E5 +// 55 | yyyy"5E74"m"6708 +// 56 | m"6708"d"65E5 +// 57 | [$-411]ge.m.d +// 58 | [$-411]ggge"5E74"m"6708"d"65E5" +// +// Number format code with unicode values provided for language glyphs where +// they occur in ko-kr language: +// +// Index | Symbol +// -------+------------------------------------------- +// 27 | yyyy"5E74" mm"6708" dd"65E5 +// 28 | mm-d +// 29 | mm-d +// 30 | mm-dd-y +// 31 | yyyy"B144" mm"C6D4" dd"C77C +// 32 | h"C2DC" mm"BD84 +// 33 | h"C2DC" mm"BD84" ss"CD08 +// 34 | yyyy-mm-d +// 35 | yyyy-mm-d +// 36 | yyyy"5E74" mm"6708" dd"65E5 +// 50 | yyyy"5E74" mm"6708" dd"65E5 +// 51 | mm-d +// 52 | yyyy-mm-d +// 53 | yyyy-mm-d +// 54 | mm-d +// 55 | yyyy-mm-d +// 56 | yyyy-mm-d +// 57 | yyyy"5E74" mm"6708" dd"65E5 +// 58 | mm-dd +// +// Number format code in th-th language: +// +// Index | Symbol +// -------+------------------------------------------- +// 59 | t +// 60 | t0.0 +// 61 | t#,## +// 62 | t#,##0.0 +// 67 | t0 +// 68 | t0.00 +// 69 | t# ?/ +// 70 | t# ??/? +// 71 | ว/ด/ปปป +// 72 | ว-ดดด-ป +// 73 | ว-ดด +// 74 | ดดด-ป +// 75 | ช:น +// 76 | ช:นน:ท +// 77 | ว/ด/ปปปป ช:น +// 78 | นน:ท +// 79 | [ช]:นน:ท +// 80 | นน:ทท. +// 81 | d/m/bb +// +// Number format code with unicode values provided for language glyphs where +// they occur in th-th language: +// +// Index | Symbol +// -------+------------------------------------------- +// 59 | t +// 60 | t0.0 +// 61 | t#,## +// 62 | t#,##0.0 +// 67 | t0 +// 68 | t0.00 +// 69 | t# ?/ +// 70 | t# ??/? +// 71 | 0E27/0E14/0E1B0E1B0E1B0E1 +// 72 | 0E27-0E140E140E14-0E1B0E1 +// 73 | 0E27-0E140E140E1 +// 74 | 0E140E140E14-0E1B0E1 +// 75 | 0E0A:0E190E1 +// 76 | 0E0A:0E190E19:0E170E1 +// 77 | 0E27/0E14/0E1B0E1B0E1B0E1B 0E0A:0E190E1 +// 78 | 0E190E19:0E170E1 +// 79 | [0E0A]:0E190E19:0E170E1 +// 80 | 0E190E19:0E170E17. +// 81 | d/m/bb +// +// Excelize built-in currency formats are shown in the following table, only +// support these types in the following table (Index number is used only for +// markup and is not used inside an Excel file and you can't get formatted value +// by the function GetCellValue) currently: +// +// Index | Symbol +// -------+--------------------------------------------------------------- +// 164 | CN¥ +// 165 | $ English (China) +// 166 | $ Cherokee (United States) +// 167 | $ Chinese (Singapore) +// 168 | $ Chinese (Taiwan) +// 169 | $ English (Australia) +// 170 | $ English (Belize) +// 171 | $ English (Canada) +// 172 | $ English (Jamaica) +// 173 | $ English (New Zealand) +// 174 | $ English (Singapore) +// 175 | $ English (Trinidad & Tobago) +// 176 | $ English (U.S. Virgin Islands) +// 177 | $ English (United States) +// 178 | $ French (Canada) +// 179 | $ Hawaiian (United States) +// 180 | $ Malay (Brunei) +// 181 | $ Quechua (Ecuador) +// 182 | $ Spanish (Chile) +// 183 | $ Spanish (Colombia) +// 184 | $ Spanish (Ecuador) +// 185 | $ Spanish (El Salvador) +// 186 | $ Spanish (Mexico) +// 187 | $ Spanish (Puerto Rico) +// 188 | $ Spanish (United States) +// 189 | $ Spanish (Uruguay) +// 190 | £ English (United Kingdom) +// 191 | £ Scottish Gaelic (United Kingdom) +// 192 | £ Welsh (United Kindom) +// 193 | ¥ Chinese (China) +// 194 | ¥ Japanese (Japan) +// 195 | ¥ Sichuan Yi (China) +// 196 | ¥ Tibetan (China) +// 197 | ¥ Uyghur (China) +// 198 | ֏ Armenian (Armenia) +// 199 | ؋ Pashto (Afghanistan) +// 200 | ؋ Persian (Afghanistan) +// 201 | ৳ Bengali (Bangladesh) +// 202 | ៛ Khmer (Cambodia) +// 203 | ₡ Spanish (Costa Rica) +// 204 | ₦ Hausa (Nigeria) +// 205 | ₦ Igbo (Nigeria) +// 206 | ₦ Yoruba (Nigeria) +// 207 | ₩ Korean (South Korea) +// 208 | ₪ Hebrew (Israel) +// 209 | ₫ Vietnamese (Vietnam) +// 210 | € Basque (Spain) +// 211 | € Breton (France) +// 212 | € Catalan (Spain) +// 213 | € Corsican (France) +// 214 | € Dutch (Belgium) +// 215 | € Dutch (Netherlands) +// 216 | € English (Ireland) +// 217 | € Estonian (Estonia) +// 218 | € Euro (€ 123) +// 219 | € Euro (123 €) +// 220 | € Finnish (Finland) +// 221 | € French (Belgium) +// 222 | € French (France) +// 223 | € French (Luxembourg) +// 224 | € French (Monaco) +// 225 | € French (Réunion) +// 226 | € Galician (Spain) +// 227 | € German (Austria) +// 228 | € German (Luxembourg) +// 229 | € Greek (Greece) +// 230 | € Inari Sami (Finland) +// 231 | € Irish (Ireland) +// 232 | € Italian (Italy) +// 233 | € Latin (Italy) +// 234 | € Latin, Serbian (Montenegro) +// 235 | € Larvian (Latvia) +// 236 | € Lithuanian (Lithuania) +// 237 | € Lower Sorbian (Germany) +// 238 | € Luxembourgish (Luxembourg) +// 239 | € Maltese (Malta) +// 240 | € Northern Sami (Finland) +// 241 | € Occitan (France) +// 242 | € Portuguese (Portugal) +// 243 | € Serbian (Montenegro) +// 244 | € Skolt Sami (Finland) +// 245 | € Slovak (Slovakia) +// 246 | € Slovenian (Slovenia) +// 247 | € Spanish (Spain) +// 248 | € Swedish (Finland) +// 249 | € Swiss German (France) +// 250 | € Upper Sorbian (Germany) +// 251 | € Western Frisian (Netherlands) +// 252 | ₭ Lao (Laos) +// 253 | ₮ Mongolian (Mongolia) +// 254 | ₮ Mongolian, Mongolian (Mongolia) +// 255 | ₱ English (Philippines) +// 256 | ₱ Filipino (Philippines) +// 257 | ₴ Ukrainian (Ukraine) +// 258 | ₸ Kazakh (Kazakhstan) +// 259 | ₹ Arabic, Kashmiri (India) +// 260 | ₹ English (India) +// 261 | ₹ Gujarati (India) +// 262 | ₹ Hindi (India) +// 263 | ₹ Kannada (India) +// 264 | ₹ Kashmiri (India) +// 265 | ₹ Konkani (India) +// 266 | ₹ Manipuri (India) +// 267 | ₹ Marathi (India) +// 268 | ₹ Nepali (India) +// 269 | ₹ Oriya (India) +// 270 | ₹ Punjabi (India) +// 271 | ₹ Sanskrit (India) +// 272 | ₹ Sindhi (India) +// 273 | ₹ Tamil (India) +// 274 | ₹ Urdu (India) +// 275 | ₺ Turkish (Turkey) +// 276 | ₼ Azerbaijani (Azerbaijan) +// 277 | ₼ Cyrillic, Azerbaijani (Azerbaijan) +// 278 | ₽ Russian (Russia) +// 279 | ₽ Sakha (Russia) +// 280 | ₾ Georgian (Georgia) +// 281 | B/. Spanish (Panama) +// 282 | Br Oromo (Ethiopia) +// 283 | Br Somali (Ethiopia) +// 284 | Br Tigrinya (Ethiopia) +// 285 | Bs Quechua (Bolivia) +// 286 | Bs Spanish (Bolivia) +// 287 | BS. Spanish (Venezuela) +// 288 | BWP Tswana (Botswana) +// 289 | C$ Spanish (Nicaragua) +// 290 | CA$ Latin, Inuktitut (Canada) +// 291 | CA$ Mohawk (Canada) +// 292 | CA$ Unified Canadian Aboriginal Syllabics, Inuktitut (Canada) +// 293 | CFA French (Mali) +// 294 | CFA French (Senegal) +// 295 | CFA Fulah (Senegal) +// 296 | CFA Wolof (Senegal) +// 297 | CHF French (Switzerland) +// 298 | CHF German (Liechtenstein) +// 299 | CHF German (Switzerland) +// 300 | CHF Italian (Switzerland) +// 301 | CHF Romansh (Switzerland) +// 302 | CLP Mapuche (Chile) +// 303 | CN¥ Mongolian, Mongolian (China) +// 304 | DZD Central Atlas Tamazight (Algeria) +// 305 | FCFA French (Cameroon) +// 306 | Ft Hungarian (Hungary) +// 307 | G French (Haiti) +// 308 | Gs. Spanish (Paraguay) +// 309 | GTQ K'iche' (Guatemala) +// 310 | HK$ Chinese (Hong Kong (China)) +// 311 | HK$ English (Hong Kong (China)) +// 312 | HRK Croatian (Croatia) +// 313 | IDR English (Indonesia) +// 314 | IQD Arbic, Central Kurdish (Iraq) +// 315 | ISK Icelandic (Iceland) +// 316 | K Burmese (Myanmar (Burma)) +// 317 | Kč Czech (Czech Republic) +// 318 | KM Bosnian (Bosnia & Herzegovina) +// 319 | KM Croatian (Bosnia & Herzegovina) +// 320 | KM Latin, Serbian (Bosnia & Herzegovina) +// 321 | kr Faroese (Faroe Islands) +// 322 | kr Northern Sami (Norway) +// 323 | kr Northern Sami (Sweden) +// 324 | kr Norwegian Bokmål (Norway) +// 325 | kr Norwegian Nynorsk (Norway) +// 326 | kr Swedish (Sweden) +// 327 | kr. Danish (Denmark) +// 328 | kr. Kalaallisut (Greenland) +// 329 | Ksh Swahili (kenya) +// 330 | L Romanian (Moldova) +// 331 | L Russian (Moldova) +// 332 | L Spanish (Honduras) +// 333 | Lekë Albanian (Albania) +// 334 | MAD Arabic, Central Atlas Tamazight (Morocco) +// 335 | MAD French (Morocco) +// 336 | MAD Tifinagh, Central Atlas Tamazight (Morocco) +// 337 | MOP$ Chinese (Macau (China)) +// 338 | MVR Divehi (Maldives) +// 339 | Nfk Tigrinya (Eritrea) +// 340 | NGN Bini (Nigeria) +// 341 | NGN Fulah (Nigeria) +// 342 | NGN Ibibio (Nigeria) +// 343 | NGN Kanuri (Nigeria) +// 344 | NOK Lule Sami (Norway) +// 345 | NOK Southern Sami (Norway) +// 346 | NZ$ Maori (New Zealand) +// 347 | PKR Sindhi (Pakistan) +// 348 | PYG Guarani (Paraguay) +// 349 | Q Spanish (Guatemala) +// 350 | R Afrikaans (South Africa) +// 351 | R English (South Africa) +// 352 | R Zulu (South Africa) +// 353 | R$ Portuguese (Brazil) +// 354 | RD$ Spanish (Dominican Republic) +// 355 | RF Kinyarwanda (Rwanda) +// 356 | RM English (Malaysia) +// 357 | RM Malay (Malaysia) +// 358 | RON Romanian (Romania) +// 359 | Rp Indonesoan (Indonesia) +// 360 | Rs Urdu (Pakistan) +// 361 | Rs. Tamil (Sri Lanka) +// 362 | RSD Latin, Serbian (Serbia) +// 363 | RSD Serbian (Serbia) +// 364 | RUB Bashkir (Russia) +// 365 | RUB Tatar (Russia) +// 366 | S/. Quechua (Peru) +// 367 | S/. Spanish (Peru) +// 368 | SEK Lule Sami (Sweden) +// 369 | SEK Southern Sami (Sweden) +// 370 | soʻm Latin, Uzbek (Uzbekistan) +// 371 | soʻm Uzbek (Uzbekistan) +// 372 | SYP Syriac (Syria) +// 373 | THB Thai (Thailand) +// 374 | TMT Turkmen (Turkmenistan) +// 375 | US$ English (Zimbabwe) +// 376 | ZAR Northern Sotho (South Africa) +// 377 | ZAR Southern Sotho (South Africa) +// 378 | ZAR Tsonga (South Africa) +// 379 | ZAR Tswana (south Africa) +// 380 | ZAR Venda (South Africa) +// 381 | ZAR Xhosa (South Africa) +// 382 | zł Polish (Poland) +// 383 | ден Macedonian (Macedonia) +// 384 | KM Cyrillic, Bosnian (Bosnia & Herzegovina) +// 385 | KM Serbian (Bosnia & Herzegovina) +// 386 | лв. Bulgarian (Bulgaria) +// 387 | p. Belarusian (Belarus) +// 388 | сом Kyrgyz (Kyrgyzstan) +// 389 | сом Tajik (Tajikistan) +// 390 | ج.م. Arabic (Egypt) +// 391 | د.أ. Arabic (Jordan) +// 392 | د.أ. Arabic (United Arab Emirates) +// 393 | د.ب. Arabic (Bahrain) +// 394 | د.ت. Arabic (Tunisia) +// 395 | د.ج. Arabic (Algeria) +// 396 | د.ع. Arabic (Iraq) +// 397 | د.ك. Arabic (Kuwait) +// 398 | د.ل. Arabic (Libya) +// 399 | د.م. Arabic (Morocco) +// 400 | ر Punjabi (Pakistan) +// 401 | ر.س. Arabic (Saudi Arabia) +// 402 | ر.ع. Arabic (Oman) +// 403 | ر.ق. Arabic (Qatar) +// 404 | ر.ي. Arabic (Yemen) +// 405 | ریال Persian (Iran) +// 406 | ل.س. Arabic (Syria) +// 407 | ل.ل. Arabic (Lebanon) +// 408 | ብር Amharic (Ethiopia) +// 409 | रू Nepaol (Nepal) +// 410 | රු. Sinhala (Sri Lanka) +// 411 | ADP +// 412 | AED +// 413 | AFA +// 414 | AFN +// 415 | ALL +// 416 | AMD +// 417 | ANG +// 418 | AOA +// 419 | ARS +// 420 | ATS +// 421 | AUD +// 422 | AWG +// 423 | AZM +// 424 | AZN +// 425 | BAM +// 426 | BBD +// 427 | BDT +// 428 | BEF +// 429 | BGL +// 430 | BGN +// 431 | BHD +// 432 | BIF +// 433 | BMD +// 434 | BND +// 435 | BOB +// 436 | BOV +// 437 | BRL +// 438 | BSD +// 439 | BTN +// 440 | BWP +// 441 | BYR +// 442 | BZD +// 443 | CAD +// 444 | CDF +// 445 | CHE +// 446 | CHF +// 447 | CHW +// 448 | CLF +// 449 | CLP +// 450 | CNY +// 451 | COP +// 452 | COU +// 453 | CRC +// 454 | CSD +// 455 | CUC +// 456 | CVE +// 457 | CYP +// 458 | CZK +// 459 | DEM +// 460 | DJF +// 461 | DKK +// 462 | DOP +// 463 | DZD +// 464 | ECS +// 465 | ECV +// 466 | EEK +// 467 | EGP +// 468 | ERN +// 469 | ESP +// 470 | ETB +// 471 | EUR +// 472 | FIM +// 473 | FJD +// 474 | FKP +// 475 | FRF +// 476 | GBP +// 477 | GEL +// 478 | GHC +// 479 | GHS +// 480 | GIP +// 481 | GMD +// 482 | GNF +// 483 | GRD +// 484 | GTQ +// 485 | GYD +// 486 | HKD +// 487 | HNL +// 488 | HRK +// 489 | HTG +// 490 | HUF +// 491 | IDR +// 492 | IEP +// 493 | ILS +// 494 | INR +// 495 | IQD +// 496 | IRR +// 497 | ISK +// 498 | ITL +// 499 | JMD +// 500 | JOD +// 501 | JPY +// 502 | KAF +// 503 | KES +// 504 | KGS +// 505 | KHR +// 506 | KMF +// 507 | KPW +// 508 | KRW +// 509 | KWD +// 510 | KYD +// 511 | KZT +// 512 | LAK +// 513 | LBP +// 514 | LKR +// 515 | LRD +// 516 | LSL +// 517 | LTL +// 518 | LUF +// 519 | LVL +// 520 | LYD +// 521 | MAD +// 522 | MDL +// 523 | MGA +// 524 | MGF +// 525 | MKD +// 526 | MMK +// 527 | MNT +// 528 | MOP +// 529 | MRO +// 530 | MTL +// 531 | MUR +// 532 | MVR +// 533 | MWK +// 534 | MXN +// 535 | MXV +// 536 | MYR +// 537 | MZM +// 538 | MZN +// 539 | NAD +// 540 | NGN +// 541 | NIO +// 542 | NLG +// 543 | NOK +// 544 | NPR +// 545 | NTD +// 546 | NZD +// 547 | OMR +// 548 | PAB +// 549 | PEN +// 550 | PGK +// 551 | PHP +// 552 | PKR +// 553 | PLN +// 554 | PTE +// 555 | PYG +// 556 | QAR +// 557 | ROL +// 558 | RON +// 559 | RSD +// 560 | RUB +// 561 | RUR +// 562 | RWF +// 563 | SAR +// 564 | SBD +// 565 | SCR +// 566 | SDD +// 567 | SDG +// 568 | SDP +// 569 | SEK +// 570 | SGD +// 571 | SHP +// 572 | SIT +// 573 | SKK +// 574 | SLL +// 575 | SOS +// 576 | SPL +// 577 | SRD +// 578 | SRG +// 579 | STD +// 580 | SVC +// 581 | SYP +// 582 | SZL +// 583 | THB +// 584 | TJR +// 585 | TJS +// 586 | TMM +// 587 | TMT +// 588 | TND +// 589 | TOP +// 590 | TRL +// 591 | TRY +// 592 | TTD +// 593 | TWD +// 594 | TZS +// 595 | UAH +// 596 | UGX +// 597 | USD +// 598 | USN +// 599 | USS +// 600 | UYI +// 601 | UYU +// 602 | UZS +// 603 | VEB +// 604 | VEF +// 605 | VND +// 606 | VUV +// 607 | WST +// 608 | XAF +// 609 | XAG +// 610 | XAU +// 611 | XB5 +// 612 | XBA +// 613 | XBB +// 614 | XBC +// 615 | XBD +// 616 | XCD +// 617 | XDR +// 618 | XFO +// 619 | XFU +// 620 | XOF +// 621 | XPD +// 622 | XPF +// 623 | XPT +// 624 | XTS +// 625 | XXX +// 626 | YER +// 627 | YUM +// 628 | ZAR +// 629 | ZMK +// 630 | ZMW +// 631 | ZWD +// 632 | ZWL +// 633 | ZWN +// 634 | ZWR +// +// Excelize support set custom number format for cell. For example, set number +// as date type in Uruguay (Spanish) format for Sheet1!A6: +// +// xlsx := excelize.NewFile() +// xlsx.SetCellValue("Sheet1", "A6", 42920.5) +// style, _ := xlsx.NewStyle(`{"custom_number_format": "[$-380A]dddd\\,\\ dd\" de \"mmmm\" de \"yyyy;@"}`) +// xlsx.SetCellStyle("Sheet1", "A6", "A6", style) +// +// Cell Sheet1!A6 in the Excel Application: martes, 04 de Julio de 2017 +// +func (f *File) NewStyle(style string) (int, error) { + var cellXfsID, fontID, borderID, fillID int + s := f.stylesReader() + fs, err := parseFormatStyleSet(style) + if err != nil { + return cellXfsID, err + } + numFmtID := setNumFmt(s, fs) + + if fs.Font != nil { + font, _ := xml.Marshal(setFont(fs)) + s.Fonts.Count++ + s.Fonts.Font = append(s.Fonts.Font, &xlsxFont{ + Font: string(font[6 : len(font)-7]), + }) + fontID = s.Fonts.Count - 1 + } + + s.Borders.Count++ + s.Borders.Border = append(s.Borders.Border, setBorders(fs)) + borderID = s.Borders.Count - 1 + + s.Fills.Count++ + s.Fills.Fill = append(s.Fills.Fill, setFills(fs, true)) + fillID = s.Fills.Count - 1 + + applyAlignment, alignment := fs.Alignment != nil, setAlignment(fs) + applyProtection, protection := fs.Protection != nil, setProtection(fs) + cellXfsID = setCellXfs(s, fontID, numFmtID, fillID, borderID, applyAlignment, applyProtection, alignment, protection) + return cellXfsID, nil +} + +// NewConditionalStyle provides a function to create style for conditional +// format by given style format. The parameters are the same as function +// NewStyle(). Note that the color field uses RGB color code and only support +// to set font, fills, alignment and borders currently. +func (f *File) NewConditionalStyle(style string) (int, error) { + s := f.stylesReader() + fs, err := parseFormatStyleSet(style) + if err != nil { + return 0, err + } + dxf := dxf{ + Fill: setFills(fs, false), + Alignment: setAlignment(fs), + Border: setBorders(fs), + } + if fs.Font != nil { + dxf.Font = setFont(fs) + } + dxfStr, _ := xml.Marshal(dxf) + if s.Dxfs == nil { + s.Dxfs = &xlsxDxfs{} + } + s.Dxfs.Count++ + s.Dxfs.Dxfs = append(s.Dxfs.Dxfs, &xlsxDxf{ + Dxf: string(dxfStr[5 : len(dxfStr)-6]), + }) + return s.Dxfs.Count - 1, nil +} + +// setFont provides a function to add font style by given cell format +// settings. +func setFont(formatStyle *formatStyle) *font { + fontUnderlineType := map[string]string{"single": "single", "double": "double"} + if formatStyle.Font.Size < 1 { + formatStyle.Font.Size = 11 + } + if formatStyle.Font.Color == "" { + formatStyle.Font.Color = "#000000" + } + f := font{ + B: formatStyle.Font.Bold, + I: formatStyle.Font.Italic, + Sz: &attrValInt{Val: formatStyle.Font.Size}, + Color: &xlsxColor{RGB: getPaletteColor(formatStyle.Font.Color)}, + Name: &attrValString{Val: formatStyle.Font.Family}, + Family: &attrValInt{Val: 2}, + } + if f.Name.Val == "" { + f.Name.Val = "Calibri" + f.Scheme = &attrValString{Val: "minor"} + } + val, ok := fontUnderlineType[formatStyle.Font.Underline] + if ok { + f.U = &attrValString{Val: val} + } + return &f +} + +// setNumFmt provides a function to check if number format code in the range +// of built-in values. +func setNumFmt(style *xlsxStyleSheet, formatStyle *formatStyle) int { + dp := "0." + numFmtID := 164 // Default custom number format code from 164. + if formatStyle.DecimalPlaces < 0 || formatStyle.DecimalPlaces > 30 { + formatStyle.DecimalPlaces = 2 + } + for i := 0; i < formatStyle.DecimalPlaces; i++ { + dp += "0" + } + if formatStyle.CustomNumFmt != nil { + return setCustomNumFmt(style, formatStyle) + } + _, ok := builtInNumFmt[formatStyle.NumFmt] + if !ok { + fc, currency := currencyNumFmt[formatStyle.NumFmt] + if !currency { + return setLangNumFmt(style, formatStyle) + } + fc = strings.Replace(fc, "0.00", dp, -1) + if formatStyle.NegRed { + fc = fc + ";[Red]" + fc + } + if style.NumFmts != nil { + numFmtID = style.NumFmts.NumFmt[len(style.NumFmts.NumFmt)-1].NumFmtID + 1 + nf := xlsxNumFmt{ + FormatCode: fc, + NumFmtID: numFmtID, + } + style.NumFmts.NumFmt = append(style.NumFmts.NumFmt, &nf) + style.NumFmts.Count++ + } else { + nf := xlsxNumFmt{ + FormatCode: fc, + NumFmtID: numFmtID, + } + numFmts := xlsxNumFmts{ + NumFmt: []*xlsxNumFmt{&nf}, + Count: 1, + } + style.NumFmts = &numFmts + } + return numFmtID + } + return formatStyle.NumFmt +} + +// setCustomNumFmt provides a function to set custom number format code. +func setCustomNumFmt(style *xlsxStyleSheet, formatStyle *formatStyle) int { + nf := xlsxNumFmt{FormatCode: *formatStyle.CustomNumFmt} + if style.NumFmts != nil { + nf.NumFmtID = style.NumFmts.NumFmt[len(style.NumFmts.NumFmt)-1].NumFmtID + 1 + style.NumFmts.NumFmt = append(style.NumFmts.NumFmt, &nf) + style.NumFmts.Count++ + } else { + nf.NumFmtID = 164 + numFmts := xlsxNumFmts{ + NumFmt: []*xlsxNumFmt{&nf}, + Count: 1, + } + style.NumFmts = &numFmts + } + return nf.NumFmtID +} + +// setLangNumFmt provides a function to set number format code with language. +func setLangNumFmt(style *xlsxStyleSheet, formatStyle *formatStyle) int { + numFmts, ok := langNumFmt[formatStyle.Lang] + if !ok { + return 0 + } + var fc string + fc, ok = numFmts[formatStyle.NumFmt] + if !ok { + return 0 + } + nf := xlsxNumFmt{FormatCode: fc} + if style.NumFmts != nil { + nf.NumFmtID = style.NumFmts.NumFmt[len(style.NumFmts.NumFmt)-1].NumFmtID + 1 + style.NumFmts.NumFmt = append(style.NumFmts.NumFmt, &nf) + style.NumFmts.Count++ + } else { + nf.NumFmtID = formatStyle.NumFmt + numFmts := xlsxNumFmts{ + NumFmt: []*xlsxNumFmt{&nf}, + Count: 1, + } + style.NumFmts = &numFmts + } + return nf.NumFmtID +} + +// setFills provides a function to add fill elements in the styles.xml by +// given cell format settings. +func setFills(formatStyle *formatStyle, fg bool) *xlsxFill { + var patterns = []string{ + "none", + "solid", + "mediumGray", + "darkGray", + "lightGray", + "darkHorizontal", + "darkVertical", + "darkDown", + "darkUp", + "darkGrid", + "darkTrellis", + "lightHorizontal", + "lightVertical", + "lightDown", + "lightUp", + "lightGrid", + "lightTrellis", + "gray125", + "gray0625", + } + + var variants = []float64{ + 90, + 0, + 45, + 135, + } + + var fill xlsxFill + switch formatStyle.Fill.Type { + case "gradient": + if len(formatStyle.Fill.Color) != 2 { + break + } + var gradient xlsxGradientFill + switch formatStyle.Fill.Shading { + case 0, 1, 2, 3: + gradient.Degree = variants[formatStyle.Fill.Shading] + case 4: + gradient.Type = "path" + case 5: + gradient.Type = "path" + gradient.Bottom = 0.5 + gradient.Left = 0.5 + gradient.Right = 0.5 + gradient.Top = 0.5 + default: + break + } + var stops []*xlsxGradientFillStop + for index, color := range formatStyle.Fill.Color { + var stop xlsxGradientFillStop + stop.Position = float64(index) + stop.Color.RGB = getPaletteColor(color) + stops = append(stops, &stop) + } + gradient.Stop = stops + fill.GradientFill = &gradient + case "pattern": + if formatStyle.Fill.Pattern > 18 || formatStyle.Fill.Pattern < 0 { + break + } + if len(formatStyle.Fill.Color) < 1 { + break + } + var pattern xlsxPatternFill + pattern.PatternType = patterns[formatStyle.Fill.Pattern] + if fg { + pattern.FgColor.RGB = getPaletteColor(formatStyle.Fill.Color[0]) + } else { + pattern.BgColor.RGB = getPaletteColor(formatStyle.Fill.Color[0]) + } + fill.PatternFill = &pattern + } + return &fill +} + +// setAlignment provides a function to formatting information pertaining to +// text alignment in cells. There are a variety of choices for how text is +// aligned both horizontally and vertically, as well as indentation settings, +// and so on. +func setAlignment(formatStyle *formatStyle) *xlsxAlignment { + var alignment xlsxAlignment + if formatStyle.Alignment != nil { + alignment.Horizontal = formatStyle.Alignment.Horizontal + alignment.Indent = formatStyle.Alignment.Indent + alignment.JustifyLastLine = formatStyle.Alignment.JustifyLastLine + alignment.ReadingOrder = formatStyle.Alignment.ReadingOrder + alignment.RelativeIndent = formatStyle.Alignment.RelativeIndent + alignment.ShrinkToFit = formatStyle.Alignment.ShrinkToFit + alignment.TextRotation = formatStyle.Alignment.TextRotation + alignment.Vertical = formatStyle.Alignment.Vertical + alignment.WrapText = formatStyle.Alignment.WrapText + } + return &alignment +} + +// setProtection provides a function to set protection properties associated +// with the cell. +func setProtection(formatStyle *formatStyle) *xlsxProtection { + var protection xlsxProtection + if formatStyle.Protection != nil { + protection.Hidden = formatStyle.Protection.Hidden + protection.Locked = formatStyle.Protection.Locked + } + return &protection +} + +// setBorders provides a function to add border elements in the styles.xml by +// given borders format settings. +func setBorders(formatStyle *formatStyle) *xlsxBorder { + var styles = []string{ + "none", + "thin", + "medium", + "dashed", + "dotted", + "thick", + "double", + "hair", + "mediumDashed", + "dashDot", + "mediumDashDot", + "dashDotDot", + "mediumDashDotDot", + "slantDashDot", + } + + var border xlsxBorder + for _, v := range formatStyle.Border { + if 0 <= v.Style && v.Style < 14 { + var color xlsxColor + color.RGB = getPaletteColor(v.Color) + switch v.Type { + case "left": + border.Left.Style = styles[v.Style] + border.Left.Color = &color + case "right": + border.Right.Style = styles[v.Style] + border.Right.Color = &color + case "top": + border.Top.Style = styles[v.Style] + border.Top.Color = &color + case "bottom": + border.Bottom.Style = styles[v.Style] + border.Bottom.Color = &color + case "diagonalUp": + border.Diagonal.Style = styles[v.Style] + border.Diagonal.Color = &color + border.DiagonalUp = true + case "diagonalDown": + border.Diagonal.Style = styles[v.Style] + border.Diagonal.Color = &color + border.DiagonalDown = true + } + } + } + return &border +} + +// setCellXfs provides a function to set describes all of the formatting for a +// cell. +func setCellXfs(style *xlsxStyleSheet, fontID, numFmtID, fillID, borderID int, applyAlignment, applyProtection bool, alignment *xlsxAlignment, protection *xlsxProtection) int { + var xf xlsxXf + xf.FontID = fontID + if fontID != 0 { + xf.ApplyFont = true + } + xf.NumFmtID = numFmtID + if numFmtID != 0 { + xf.ApplyNumberFormat = true + } + xf.FillID = fillID + xf.BorderID = borderID + style.CellXfs.Count++ + xf.Alignment = alignment + xf.ApplyAlignment = applyAlignment + if applyProtection { + xf.ApplyProtection = applyProtection + xf.Protection = protection + } + xfID := 0 + xf.XfID = &xfID + style.CellXfs.Xf = append(style.CellXfs.Xf, xf) + return style.CellXfs.Count - 1 +} + +// SetCellStyle provides a function to add style attribute for cells by given +// worksheet name, coordinate area and style ID. Note that diagonalDown and +// diagonalUp type border should be use same color in the same coordinate +// area. +// +// For example create a borders of cell H9 on Sheet1: +// +// style, err := xlsx.NewStyle(`{"border":[{"type":"left","color":"0000FF","style":3},{"type":"top","color":"00FF00","style":4},{"type":"bottom","color":"FFFF00","style":5},{"type":"right","color":"FF0000","style":6},{"type":"diagonalDown","color":"A020F0","style":7},{"type":"diagonalUp","color":"A020F0","style":8}]}`) +// if err != nil { +// fmt.Println(err) +// } +// xlsx.SetCellStyle("Sheet1", "H9", "H9", style) +// +// Set gradient fill with vertical variants shading styles for cell H9 on +// Sheet1: +// +// style, err := xlsx.NewStyle(`{"fill":{"type":"gradient","color":["#FFFFFF","#E0EBF5"],"shading":1}}`) +// if err != nil { +// fmt.Println(err) +// } +// xlsx.SetCellStyle("Sheet1", "H9", "H9", style) +// +// Set solid style pattern fill for cell H9 on Sheet1: +// +// style, err := xlsx.NewStyle(`{"fill":{"type":"pattern","color":["#E0EBF5"],"pattern":1}}`) +// if err != nil { +// fmt.Println(err) +// } +// xlsx.SetCellStyle("Sheet1", "H9", "H9", style) +// +// Set alignment style for cell H9 on Sheet1: +// +// style, err := xlsx.NewStyle(`{"alignment":{"horizontal":"center","ident":1,"justify_last_line":true,"reading_order":0,"relative_indent":1,"shrink_to_fit":true,"text_rotation":45,"vertical":"","wrap_text":true}}`) +// if err != nil { +// fmt.Println(err) +// } +// xlsx.SetCellStyle("Sheet1", "H9", "H9", style) +// +// Dates and times in Excel are represented by real numbers, for example "Apr 7 +// 2017 12:00 PM" is represented by the number 42920.5. Set date and time format +// for cell H9 on Sheet1: +// +// xlsx.SetCellValue("Sheet1", "H9", 42920.5) +// style, err := xlsx.NewStyle(`{"number_format": 22}`) +// if err != nil { +// fmt.Println(err) +// } +// xlsx.SetCellStyle("Sheet1", "H9", "H9", style) +// +// Set font style for cell H9 on Sheet1: +// +// style, err := xlsx.NewStyle(`{"font":{"bold":true,"italic":true,"family":"Berlin Sans FB Demi","size":36,"color":"#777777"}}`) +// if err != nil { +// fmt.Println(err) +// } +// xlsx.SetCellStyle("Sheet1", "H9", "H9", style) +// +// Hide and lock for cell H9 on Sheet1: +// +// style, err := xlsx.NewStyle(`{"protection":{"hidden":true, "locked":true}}`) +// if err != nil { +// fmt.Println(err) +// } +// xlsx.SetCellStyle("Sheet1", "H9", "H9", style) +// +func (f *File) SetCellStyle(sheet, hcell, vcell string, styleID int) { + hcell = strings.ToUpper(hcell) + vcell = strings.ToUpper(vcell) + + // Coordinate conversion, convert C1:B3 to 2,0,1,2. + hcol := string(strings.Map(letterOnlyMapF, hcell)) + hrow, err := strconv.Atoi(strings.Map(intOnlyMapF, hcell)) + if err != nil { + return + } + hyAxis := hrow - 1 + hxAxis := TitleToNumber(hcol) + + vcol := string(strings.Map(letterOnlyMapF, vcell)) + vrow, err := strconv.Atoi(strings.Map(intOnlyMapF, vcell)) + if err != nil { + return + } + vyAxis := vrow - 1 + vxAxis := TitleToNumber(vcol) + + // Correct the coordinate area, such correct C1:B3 to B1:C3. + if vxAxis < hxAxis { + vxAxis, hxAxis = hxAxis, vxAxis + } + + if vyAxis < hyAxis { + vyAxis, hyAxis = hyAxis, vyAxis + } + + xlsx := f.workSheetReader(sheet) + + completeRow(xlsx, vyAxis+1, vxAxis+1) + completeCol(xlsx, vyAxis+1, vxAxis+1) + + for r := hyAxis; r <= vyAxis; r++ { + for k := hxAxis; k <= vxAxis; k++ { + xlsx.SheetData.Row[r].C[k].S = styleID + } + } +} + +// SetConditionalFormat provides a function to create conditional formatting +// rule for cell value. Conditional formatting is a feature of Excel which +// allows you to apply a format to a cell or a range of cells based on certain +// criteria. +// +// The type option is a required parameter and it has no default value. +// Allowable type values and their associated parameters are: +// +// Type | Parameters +// ---------------+------------------------------------ +// cell | criteria +// | value +// | minimum +// | maximum +// date | criteria +// | value +// | minimum +// | maximum +// time_period | criteria +// text | criteria +// | value +// average | criteria +// duplicate | (none) +// unique | (none) +// top | criteria +// | value +// bottom | criteria +// | value +// blanks | (none) +// no_blanks | (none) +// errors | (none) +// no_errors | (none) +// 2_color_scale | min_type +// | max_type +// | min_value +// | max_value +// | min_color +// | max_color +// 3_color_scale | min_type +// | mid_type +// | max_type +// | min_value +// | mid_value +// | max_value +// | min_color +// | mid_color +// | max_color +// data_bar | min_type +// | max_type +// | min_value +// | max_value +// | bar_color +// formula | criteria +// +// The criteria parameter is used to set the criteria by which the cell data +// will be evaluated. It has no default value. The most common criteria as +// applied to {"type":"cell"} are: +// +// between | +// not between | +// equal to | == +// not equal to | != +// greater than | > +// less than | < +// greater than or equal to | >= +// less than or equal to | <= +// +// You can either use Excel's textual description strings, in the first column +// above, or the more common symbolic alternatives. +// +// Additional criteria which are specific to other conditional format types are +// shown in the relevant sections below. +// +// value: The value is generally used along with the criteria parameter to set +// the rule by which the cell data will be evaluated: +// +// xlsx.SetConditionalFormat("Sheet1", "D1:D10", fmt.Sprintf(`[{"type":"cell","criteria":">","format":%d,"value":"6"}]`, format)) +// +// The value property can also be an cell reference: +// +// xlsx.SetConditionalFormat("Sheet1", "D1:D10", fmt.Sprintf(`[{"type":"cell","criteria":">","format":%d,"value":"$C$1"}]`, format)) +// +// type: format - The format parameter is used to specify the format that will +// be applied to the cell when the conditional formatting criterion is met. The +// format is created using the NewConditionalStyle() method in the same way as +// cell formats: +// +// format, err = xlsx.NewConditionalStyle(`{"font":{"color":"#9A0511"},"fill":{"type":"pattern","color":["#FEC7CE"],"pattern":1}}`) +// if err != nil { +// fmt.Println(err) +// } +// xlsx.SetConditionalFormat("Sheet1", "A1:A10", fmt.Sprintf(`[{"type":"cell","criteria":">","format":%d,"value":"6"}]`, format)) +// +// Note: In Excel, a conditional format is superimposed over the existing cell +// format and not all cell format properties can be modified. Properties that +// cannot be modified in a conditional format are font name, font size, +// superscript and subscript, diagonal borders, all alignment properties and all +// protection properties. +// +// Excel specifies some default formats to be used with conditional formatting. +// These can be replicated using the following excelize formats: +// +// // Rose format for bad conditional. +// format1, err = xlsx.NewConditionalStyle(`{"font":{"color":"#9A0511"},"fill":{"type":"pattern","color":["#FEC7CE"],"pattern":1}}`) +// +// // Light yellow format for neutral conditional. +// format2, err = xlsx.NewConditionalStyle(`{"font":{"color":"#9B5713"},"fill":{"type":"pattern","color":["#FEEAA0"],"pattern":1}}`) +// +// // Light green format for good conditional. +// format3, err = xlsx.NewConditionalStyle(`{"font":{"color":"#09600B"},"fill":{"type":"pattern","color":["#C7EECF"],"pattern":1}}`) +// +// type: minimum - The minimum parameter is used to set the lower limiting value +// when the criteria is either "between" or "not between". +// +// // Hightlight cells rules: between... +// xlsx.SetConditionalFormat("Sheet1", "A1:A10", fmt.Sprintf(`[{"type":"cell","criteria":"between","format":%d,"minimum":"6","maximum":"8"}]`, format)) +// +// type: maximum - The maximum parameter is used to set the upper limiting value +// when the criteria is either "between" or "not between". See the previous +// example. +// +// type: average - The average type is used to specify Excel's "Average" style +// conditional format: +// +// // Top/Bottom rules: Above Average... +// xlsx.SetConditionalFormat("Sheet1", "A1:A10", fmt.Sprintf(`[{"type":"average","criteria":"=","format":%d, "above_average": true}]`, format1)) +// +// // Top/Bottom rules: Below Average... +// xlsx.SetConditionalFormat("Sheet1", "B1:B10", fmt.Sprintf(`[{"type":"average","criteria":"=","format":%d, "above_average": false}]`, format2)) +// +// type: duplicate - The duplicate type is used to highlight duplicate cells in a range: +// +// // Hightlight cells rules: Duplicate Values... +// xlsx.SetConditionalFormat("Sheet1", "A1:A10", fmt.Sprintf(`[{"type":"duplicate","criteria":"=","format":%d}]`, format)) +// +// type: unique - The unique type is used to highlight unique cells in a range: +// +// // Hightlight cells rules: Not Equal To... +// xlsx.SetConditionalFormat("Sheet1", "A1:A10", fmt.Sprintf(`[{"type":"unique","criteria":"=","format":%d}]`, format)) +// +// type: top - The top type is used to specify the top n values by number or percentage in a range: +// +// // Top/Bottom rules: Top 10. +// xlsx.SetConditionalFormat("Sheet1", "H1:H10", fmt.Sprintf(`[{"type":"top","criteria":"=","format":%d,"value":"6"}]`, format)) +// +// The criteria can be used to indicate that a percentage condition is required: +// +// xlsx.SetConditionalFormat("Sheet1", "A1:A10", fmt.Sprintf(`[{"type":"top","criteria":"=","format":%d,"value":"6","percent":true}]`, format)) +// +// type: 2_color_scale - The 2_color_scale type is used to specify Excel's "2 +// Color Scale" style conditional format: +// +// // Color scales: 2 color. +// xlsx.SetConditionalFormat("Sheet1", "A1:A10", `[{"type":"2_color_scale","criteria":"=","min_type":"min","max_type":"max","min_color":"#F8696B","max_color":"#63BE7B"}]`) +// +// This conditional type can be modified with min_type, max_type, min_value, +// max_value, min_color and max_color, see below. +// +// type: 3_color_scale - The 3_color_scale type is used to specify Excel's "3 +// Color Scale" style conditional format: +// +// // Color scales: 3 color. +// xlsx.SetConditionalFormat("Sheet1", "A1:A10", `[{"type":"3_color_scale","criteria":"=","min_type":"min","mid_type":"percentile","max_type":"max","min_color":"#F8696B","mid_color":"#FFEB84","max_color":"#63BE7B"}]`) +// +// This conditional type can be modified with min_type, mid_type, max_type, +// min_value, mid_value, max_value, min_color, mid_color and max_color, see +// below. +// +// type: data_bar - The data_bar type is used to specify Excel's "Data Bar" +// style conditional format. +// +// min_type - The min_type and max_type properties are available when the conditional formatting type is 2_color_scale, 3_color_scale or data_bar. The mid_type is available for 3_color_scale. The properties are used as follows: +// +// // Data Bars: Gradient Fill. +// xlsx.SetConditionalFormat("Sheet1", "K1:K10", `[{"type":"data_bar", "criteria":"=", "min_type":"min","max_type":"max","bar_color":"#638EC6"}]`) +// +// The available min/mid/max types are: +// +// min (for min_type only) +// num +// percent +// percentile +// formula +// max (for max_type only) +// +// mid_type - Used for 3_color_scale. Same as min_type, see above. +// +// max_type - Same as min_type, see above. +// +// min_value - The min_value and max_value properties are available when the +// conditional formatting type is 2_color_scale, 3_color_scale or data_bar. The +// mid_value is available for 3_color_scale. +// +// mid_value - Used for 3_color_scale. Same as min_value, see above. +// +// max_value - Same as min_value, see above. +// +// min_color - The min_color and max_color properties are available when the +// conditional formatting type is 2_color_scale, 3_color_scale or data_bar. +// The mid_color is available for 3_color_scale. The properties are used as +// follows: +// +// // Color scales: 3 color. +// xlsx.SetConditionalFormat("Sheet1", "B1:B10", `[{"type":"3_color_scale","criteria":"=","min_type":"min","mid_type":"percentile","max_type":"max","min_color":"#F8696B","mid_color":"#FFEB84","max_color":"#63BE7B"}]`) +// +// mid_color - Used for 3_color_scale. Same as min_color, see above. +// +// max_color - Same as min_color, see above. +// +// bar_color - Used for data_bar. Same as min_color, see above. +// +func (f *File) SetConditionalFormat(sheet, area, formatSet string) error { + var format []*formatConditional + err := json.Unmarshal([]byte(formatSet), &format) + if err != nil { + return err + } + drawContFmtFunc := map[string]func(p int, ct string, fmtCond *formatConditional) *xlsxCfRule{ + "cellIs": drawCondFmtCellIs, + "top10": drawCondFmtTop10, + "aboveAverage": drawCondFmtAboveAverage, + "duplicateValues": drawCondFmtDuplicateUniqueValues, + "uniqueValues": drawCondFmtDuplicateUniqueValues, + "2_color_scale": drawCondFmtColorScale, + "3_color_scale": drawCondFmtColorScale, + "dataBar": drawCondFmtDataBar, + "expression": drawConfFmtExp, + } + + xlsx := f.workSheetReader(sheet) + cfRule := []*xlsxCfRule{} + for p, v := range format { + var vt, ct string + var ok bool + // "type" is a required parameter, check for valid validation types. + vt, ok = validType[v.Type] + if ok { + // Check for valid criteria types. + ct, ok = criteriaType[v.Criteria] + if ok || vt == "expression" { + drawfunc, ok := drawContFmtFunc[vt] + if ok { + cfRule = append(cfRule, drawfunc(p, ct, v)) + } + } + } + } + + xlsx.ConditionalFormatting = append(xlsx.ConditionalFormatting, &xlsxConditionalFormatting{ + SQRef: area, + CfRule: cfRule, + }) + return err +} + +// drawCondFmtCellIs provides a function to create conditional formatting rule +// for cell value (include between, not between, equal, not equal, greater +// than and less than) by given priority, criteria type and format settings. +func drawCondFmtCellIs(p int, ct string, format *formatConditional) *xlsxCfRule { + c := &xlsxCfRule{ + Priority: p + 1, + Type: validType[format.Type], + Operator: ct, + DxfID: &format.Format, + } + // "between" and "not between" criteria require 2 values. + _, ok := map[string]bool{"between": true, "notBetween": true}[ct] + if ok { + c.Formula = append(c.Formula, format.Minimum) + c.Formula = append(c.Formula, format.Maximum) + } + _, ok = map[string]bool{"equal": true, "notEqual": true, "greaterThan": true, "lessThan": true}[ct] + if ok { + c.Formula = append(c.Formula, format.Value) + } + return c +} + +// drawCondFmtTop10 provides a function to create conditional formatting rule +// for top N (default is top 10) by given priority, criteria type and format +// settings. +func drawCondFmtTop10(p int, ct string, format *formatConditional) *xlsxCfRule { + c := &xlsxCfRule{ + Priority: p + 1, + Type: validType[format.Type], + Rank: 10, + DxfID: &format.Format, + Percent: format.Percent, + } + rank, err := strconv.Atoi(format.Value) + if err == nil { + c.Rank = rank + } + return c +} + +// drawCondFmtAboveAverage provides a function to create conditional +// formatting rule for above average and below average by given priority, +// criteria type and format settings. +func drawCondFmtAboveAverage(p int, ct string, format *formatConditional) *xlsxCfRule { + return &xlsxCfRule{ + Priority: p + 1, + Type: validType[format.Type], + AboveAverage: &format.AboveAverage, + DxfID: &format.Format, + } +} + +// drawCondFmtDuplicateUniqueValues provides a function to create conditional +// formatting rule for duplicate and unique values by given priority, criteria +// type and format settings. +func drawCondFmtDuplicateUniqueValues(p int, ct string, format *formatConditional) *xlsxCfRule { + return &xlsxCfRule{ + Priority: p + 1, + Type: validType[format.Type], + DxfID: &format.Format, + } +} + +// drawCondFmtColorScale provides a function to create conditional formatting +// rule for color scale (include 2 color scale and 3 color scale) by given +// priority, criteria type and format settings. +func drawCondFmtColorScale(p int, ct string, format *formatConditional) *xlsxCfRule { + minValue := format.MinValue + if minValue == "" { + minValue = "0" + } + maxValue := format.MaxValue + if maxValue == "" { + maxValue = "0" + } + midValue := format.MidValue + if midValue == "" { + midValue = "50" + } + + c := &xlsxCfRule{ + Priority: p + 1, + Type: "colorScale", + ColorScale: &xlsxColorScale{ + Cfvo: []*xlsxCfvo{ + {Type: format.MinType, Val: minValue}, + }, + Color: []*xlsxColor{ + {RGB: getPaletteColor(format.MinColor)}, + }, + }, + } + if validType[format.Type] == "3_color_scale" { + c.ColorScale.Cfvo = append(c.ColorScale.Cfvo, &xlsxCfvo{Type: format.MidType, Val: midValue}) + c.ColorScale.Color = append(c.ColorScale.Color, &xlsxColor{RGB: getPaletteColor(format.MidColor)}) + } + c.ColorScale.Cfvo = append(c.ColorScale.Cfvo, &xlsxCfvo{Type: format.MaxType, Val: maxValue}) + c.ColorScale.Color = append(c.ColorScale.Color, &xlsxColor{RGB: getPaletteColor(format.MaxColor)}) + return c +} + +// drawCondFmtDataBar provides a function to create conditional formatting +// rule for data bar by given priority, criteria type and format settings. +func drawCondFmtDataBar(p int, ct string, format *formatConditional) *xlsxCfRule { + return &xlsxCfRule{ + Priority: p + 1, + Type: validType[format.Type], + DataBar: &xlsxDataBar{ + Cfvo: []*xlsxCfvo{{Type: format.MinType}, {Type: format.MaxType}}, + Color: []*xlsxColor{{RGB: getPaletteColor(format.BarColor)}}, + }, + } +} + +// drawConfFmtExp provides a function to create conditional formatting rule +// for expression by given priority, criteria type and format settings. +func drawConfFmtExp(p int, ct string, format *formatConditional) *xlsxCfRule { + return &xlsxCfRule{ + Priority: p + 1, + Type: validType[format.Type], + Formula: []string{format.Criteria}, + DxfID: &format.Format, + } +} + +// getPaletteColor provides a function to convert the RBG color by given +// string. +func getPaletteColor(color string) string { + return "FF" + strings.Replace(strings.ToUpper(color), "#", "", -1) +} + +// themeReader provides a function to get the pointer to the xl/theme/theme1.xml +// structure after deserialization. +func (f *File) themeReader() *xlsxTheme { + var theme xlsxTheme + _ = xml.Unmarshal(namespaceStrictToTransitional(f.readXML("xl/theme/theme1.xml")), &theme) + return &theme +} + +// ThemeColor applied the color with tint value. +func ThemeColor(baseColor string, tint float64) string { + if tint == 0 { + return "FF" + baseColor + } + r, _ := strconv.ParseInt(baseColor[0:2], 16, 64) + g, _ := strconv.ParseInt(baseColor[2:4], 16, 64) + b, _ := strconv.ParseInt(baseColor[4:6], 16, 64) + h, s, l := RGBToHSL(uint8(r), uint8(g), uint8(b)) + if tint < 0 { + l *= (1 + tint) + } else { + l = l*(1-tint) + (1 - (1 - tint)) + } + br, bg, bb := HSLToRGB(h, s, l) + return fmt.Sprintf("FF%02X%02X%02X", br, bg, bb) +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/table.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/table.go new file mode 100644 index 0000000000..7c7e061921 --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/table.go @@ -0,0 +1,461 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. + +package excelize + +import ( + "encoding/json" + "encoding/xml" + "fmt" + "regexp" + "strconv" + "strings" +) + +// parseFormatTableSet provides a function to parse the format settings of the +// table with default value. +func parseFormatTableSet(formatSet string) (*formatTable, error) { + format := formatTable{ + TableStyle: "", + ShowRowStripes: true, + } + err := json.Unmarshal(parseFormatSet(formatSet), &format) + return &format, err +} + +// AddTable provides the method to add table in a worksheet by given worksheet +// name, coordinate area and format set. For example, create a table of A1:D5 +// on Sheet1: +// +// xlsx.AddTable("Sheet1", "A1", "D5", ``) +// +// Create a table of F2:H6 on Sheet2 with format set: +// +// xlsx.AddTable("Sheet2", "F2", "H6", `{"table_name":"table","table_style":"TableStyleMedium2", "show_first_column":true,"show_last_column":true,"show_row_stripes":false,"show_column_stripes":true}`) +// +// Note that the table at least two lines include string type header. Multiple +// tables coordinate areas can't have an intersection. +// +// table_name: The name of the table, in the same worksheet name of the table should be unique +// +// table_style: The built-in table style names +// +// TableStyleLight1 - TableStyleLight21 +// TableStyleMedium1 - TableStyleMedium28 +// TableStyleDark1 - TableStyleDark11 +// +func (f *File) AddTable(sheet, hcell, vcell, format string) error { + formatSet, err := parseFormatTableSet(format) + if err != nil { + return err + } + hcell = strings.ToUpper(hcell) + vcell = strings.ToUpper(vcell) + // Coordinate conversion, convert C1:B3 to 2,0,1,2. + hcol := string(strings.Map(letterOnlyMapF, hcell)) + hrow, _ := strconv.Atoi(strings.Map(intOnlyMapF, hcell)) + hyAxis := hrow - 1 + hxAxis := TitleToNumber(hcol) + + vcol := string(strings.Map(letterOnlyMapF, vcell)) + vrow, _ := strconv.Atoi(strings.Map(intOnlyMapF, vcell)) + vyAxis := vrow - 1 + vxAxis := TitleToNumber(vcol) + if vxAxis < hxAxis { + vxAxis, hxAxis = hxAxis, vxAxis + } + if vyAxis < hyAxis { + vyAxis, hyAxis = hyAxis, vyAxis + } + tableID := f.countTables() + 1 + sheetRelationshipsTableXML := "../tables/table" + strconv.Itoa(tableID) + ".xml" + tableXML := strings.Replace(sheetRelationshipsTableXML, "..", "xl", -1) + // Add first table for given sheet. + rID := f.addSheetRelationships(sheet, SourceRelationshipTable, sheetRelationshipsTableXML, "") + f.addSheetTable(sheet, rID) + f.addTable(sheet, tableXML, hxAxis, hyAxis, vxAxis, vyAxis, tableID, formatSet) + f.addContentTypePart(tableID, "table") + return err +} + +// countTables provides a function to get table files count storage in the +// folder xl/tables. +func (f *File) countTables() int { + count := 0 + for k := range f.XLSX { + if strings.Contains(k, "xl/tables/table") { + count++ + } + } + return count +} + +// addSheetTable provides a function to add tablePart element to +// xl/worksheets/sheet%d.xml by given worksheet name and relationship index. +func (f *File) addSheetTable(sheet string, rID int) { + xlsx := f.workSheetReader(sheet) + table := &xlsxTablePart{ + RID: "rId" + strconv.Itoa(rID), + } + if xlsx.TableParts == nil { + xlsx.TableParts = &xlsxTableParts{} + } + xlsx.TableParts.Count++ + xlsx.TableParts.TableParts = append(xlsx.TableParts.TableParts, table) +} + +// addTable provides a function to add table by given worksheet name, +// coordinate area and format set. +func (f *File) addTable(sheet, tableXML string, hxAxis, hyAxis, vxAxis, vyAxis, i int, formatSet *formatTable) { + // Correct the minimum number of rows, the table at least two lines. + if hyAxis == vyAxis { + vyAxis++ + } + // Correct table reference coordinate area, such correct C1:B3 to B1:C3. + ref := ToAlphaString(hxAxis) + strconv.Itoa(hyAxis+1) + ":" + ToAlphaString(vxAxis) + strconv.Itoa(vyAxis+1) + tableColumn := []*xlsxTableColumn{} + idx := 0 + for i := hxAxis; i <= vxAxis; i++ { + idx++ + cell := ToAlphaString(i) + strconv.Itoa(hyAxis+1) + name := f.GetCellValue(sheet, cell) + if _, err := strconv.Atoi(name); err == nil { + f.SetCellStr(sheet, cell, name) + } + if name == "" { + name = "Column" + strconv.Itoa(idx) + f.SetCellStr(sheet, cell, name) + } + tableColumn = append(tableColumn, &xlsxTableColumn{ + ID: idx, + Name: name, + }) + } + name := formatSet.TableName + if name == "" { + name = "Table" + strconv.Itoa(i) + } + t := xlsxTable{ + XMLNS: NameSpaceSpreadSheet, + ID: i, + Name: name, + DisplayName: name, + Ref: ref, + AutoFilter: &xlsxAutoFilter{ + Ref: ref, + }, + TableColumns: &xlsxTableColumns{ + Count: idx, + TableColumn: tableColumn, + }, + TableStyleInfo: &xlsxTableStyleInfo{ + Name: formatSet.TableStyle, + ShowFirstColumn: formatSet.ShowFirstColumn, + ShowLastColumn: formatSet.ShowLastColumn, + ShowRowStripes: formatSet.ShowRowStripes, + ShowColumnStripes: formatSet.ShowColumnStripes, + }, + } + table, _ := xml.Marshal(t) + f.saveFileList(tableXML, table) +} + +// parseAutoFilterSet provides a function to parse the settings of the auto +// filter. +func parseAutoFilterSet(formatSet string) (*formatAutoFilter, error) { + format := formatAutoFilter{} + err := json.Unmarshal([]byte(formatSet), &format) + return &format, err +} + +// AutoFilter provides the method to add auto filter in a worksheet by given +// worksheet name, coordinate area and settings. An autofilter in Excel is a +// way of filtering a 2D range of data based on some simple criteria. For +// example applying an autofilter to a cell range A1:D4 in the Sheet1: +// +// err = xlsx.AutoFilter("Sheet1", "A1", "D4", "") +// +// Filter data in an autofilter: +// +// err = xlsx.AutoFilter("Sheet1", "A1", "D4", `{"column":"B","expression":"x != blanks"}`) +// +// column defines the filter columns in a autofilter range based on simple +// criteria +// +// It isn't sufficient to just specify the filter condition. You must also +// hide any rows that don't match the filter condition. Rows are hidden using +// the SetRowVisible() method. Excelize can't filter rows automatically since +// this isn't part of the file format. +// +// Setting a filter criteria for a column: +// +// expression defines the conditions, the following operators are available +// for setting the filter criteria: +// +// == +// != +// > +// < +// >= +// <= +// and +// or +// +// An expression can comprise a single statement or two statements separated +// by the 'and' and 'or' operators. For example: +// +// x < 2000 +// x > 2000 +// x == 2000 +// x > 2000 and x < 5000 +// x == 2000 or x == 5000 +// +// Filtering of blank or non-blank data can be achieved by using a value of +// Blanks or NonBlanks in the expression: +// +// x == Blanks +// x == NonBlanks +// +// Excel also allows some simple string matching operations: +// +// x == b* // begins with b +// x != b* // doesnt begin with b +// x == *b // ends with b +// x != *b // doesnt end with b +// x == *b* // contains b +// x != *b* // doesn't contains b +// +// You can also use '*' to match any character or number and '?' to match any +// single character or number. No other regular expression quantifier is +// supported by Excel's filters. Excel's regular expression characters can be +// escaped using '~'. +// +// The placeholder variable x in the above examples can be replaced by any +// simple string. The actual placeholder name is ignored internally so the +// following are all equivalent: +// +// x < 2000 +// col < 2000 +// Price < 2000 +// +func (f *File) AutoFilter(sheet, hcell, vcell, format string) error { + formatSet, _ := parseAutoFilterSet(format) + + hcell = strings.ToUpper(hcell) + vcell = strings.ToUpper(vcell) + + // Coordinate conversion, convert C1:B3 to 2,0,1,2. + hcol := string(strings.Map(letterOnlyMapF, hcell)) + hrow, _ := strconv.Atoi(strings.Map(intOnlyMapF, hcell)) + hyAxis := hrow - 1 + hxAxis := TitleToNumber(hcol) + + vcol := string(strings.Map(letterOnlyMapF, vcell)) + vrow, _ := strconv.Atoi(strings.Map(intOnlyMapF, vcell)) + vyAxis := vrow - 1 + vxAxis := TitleToNumber(vcol) + + if vxAxis < hxAxis { + vxAxis, hxAxis = hxAxis, vxAxis + } + + if vyAxis < hyAxis { + vyAxis, hyAxis = hyAxis, vyAxis + } + ref := ToAlphaString(hxAxis) + strconv.Itoa(hyAxis+1) + ":" + ToAlphaString(vxAxis) + strconv.Itoa(vyAxis+1) + refRange := vxAxis - hxAxis + return f.autoFilter(sheet, ref, refRange, hxAxis, formatSet) +} + +// autoFilter provides a function to extract the tokens from the filter +// expression. The tokens are mainly non-whitespace groups. +func (f *File) autoFilter(sheet, ref string, refRange, hxAxis int, formatSet *formatAutoFilter) error { + xlsx := f.workSheetReader(sheet) + if xlsx.SheetPr != nil { + xlsx.SheetPr.FilterMode = true + } + xlsx.SheetPr = &xlsxSheetPr{FilterMode: true} + filter := &xlsxAutoFilter{ + Ref: ref, + } + xlsx.AutoFilter = filter + if formatSet.Column == "" || formatSet.Expression == "" { + return nil + } + col := TitleToNumber(formatSet.Column) + offset := col - hxAxis + if offset < 0 || offset > refRange { + return fmt.Errorf("incorrect index of column '%s'", formatSet.Column) + } + filter.FilterColumn = &xlsxFilterColumn{ + ColID: offset, + } + re := regexp.MustCompile(`"(?:[^"]|"")*"|\S+`) + token := re.FindAllString(formatSet.Expression, -1) + if len(token) != 3 && len(token) != 7 { + return fmt.Errorf("incorrect number of tokens in criteria '%s'", formatSet.Expression) + } + expressions, tokens, err := f.parseFilterExpression(formatSet.Expression, token) + if err != nil { + return err + } + f.writeAutoFilter(filter, expressions, tokens) + xlsx.AutoFilter = filter + return nil +} + +// writeAutoFilter provides a function to check for single or double custom +// filters as default filters and handle them accordingly. +func (f *File) writeAutoFilter(filter *xlsxAutoFilter, exp []int, tokens []string) { + if len(exp) == 1 && exp[0] == 2 { + // Single equality. + filters := []*xlsxFilter{} + filters = append(filters, &xlsxFilter{Val: tokens[0]}) + filter.FilterColumn.Filters = &xlsxFilters{Filter: filters} + } else if len(exp) == 3 && exp[0] == 2 && exp[1] == 1 && exp[2] == 2 { + // Double equality with "or" operator. + filters := []*xlsxFilter{} + for _, v := range tokens { + filters = append(filters, &xlsxFilter{Val: v}) + } + filter.FilterColumn.Filters = &xlsxFilters{Filter: filters} + } else { + // Non default custom filter. + expRel := map[int]int{0: 0, 1: 2} + andRel := map[int]bool{0: true, 1: false} + for k, v := range tokens { + f.writeCustomFilter(filter, exp[expRel[k]], v) + if k == 1 { + filter.FilterColumn.CustomFilters.And = andRel[exp[k]] + } + } + } +} + +// writeCustomFilter provides a function to write the element. +func (f *File) writeCustomFilter(filter *xlsxAutoFilter, operator int, val string) { + operators := map[int]string{ + 1: "lessThan", + 2: "equal", + 3: "lessThanOrEqual", + 4: "greaterThan", + 5: "notEqual", + 6: "greaterThanOrEqual", + 22: "equal", + } + customFilter := xlsxCustomFilter{ + Operator: operators[operator], + Val: val, + } + if filter.FilterColumn.CustomFilters != nil { + filter.FilterColumn.CustomFilters.CustomFilter = append(filter.FilterColumn.CustomFilters.CustomFilter, &customFilter) + } else { + customFilters := []*xlsxCustomFilter{} + customFilters = append(customFilters, &customFilter) + filter.FilterColumn.CustomFilters = &xlsxCustomFilters{CustomFilter: customFilters} + } +} + +// parseFilterExpression provides a function to converts the tokens of a +// possibly conditional expression into 1 or 2 sub expressions for further +// parsing. +// +// Examples: +// +// ('x', '==', 2000) -> exp1 +// ('x', '>', 2000, 'and', 'x', '<', 5000) -> exp1 and exp2 +// +func (f *File) parseFilterExpression(expression string, tokens []string) ([]int, []string, error) { + expressions := []int{} + t := []string{} + if len(tokens) == 7 { + // The number of tokens will be either 3 (for 1 expression) or 7 (for 2 + // expressions). + conditional := 0 + c := tokens[3] + re, _ := regexp.Match(`(or|\|\|)`, []byte(c)) + if re { + conditional = 1 + } + expression1, token1, err := f.parseFilterTokens(expression, tokens[0:3]) + if err != nil { + return expressions, t, err + } + expression2, token2, err := f.parseFilterTokens(expression, tokens[4:7]) + if err != nil { + return expressions, t, err + } + expressions = []int{expression1[0], conditional, expression2[0]} + t = []string{token1, token2} + } else { + exp, token, err := f.parseFilterTokens(expression, tokens) + if err != nil { + return expressions, t, err + } + expressions = exp + t = []string{token} + } + return expressions, t, nil +} + +// parseFilterTokens provides a function to parse the 3 tokens of a filter +// expression and return the operator and token. +func (f *File) parseFilterTokens(expression string, tokens []string) ([]int, string, error) { + operators := map[string]int{ + "==": 2, + "=": 2, + "=~": 2, + "eq": 2, + "!=": 5, + "!~": 5, + "ne": 5, + "<>": 5, + "<": 1, + "<=": 3, + ">": 4, + ">=": 6, + } + operator, ok := operators[strings.ToLower(tokens[1])] + if !ok { + // Convert the operator from a number to a descriptive string. + return []int{}, "", fmt.Errorf("unknown operator: %s", tokens[1]) + } + token := tokens[2] + // Special handling for Blanks/NonBlanks. + re, _ := regexp.Match("blanks|nonblanks", []byte(strings.ToLower(token))) + if re { + // Only allow Equals or NotEqual in this context. + if operator != 2 && operator != 5 { + return []int{operator}, token, fmt.Errorf("the operator '%s' in expression '%s' is not valid in relation to Blanks/NonBlanks'", tokens[1], expression) + } + token = strings.ToLower(token) + // The operator should always be 2 (=) to flag a "simple" equality in + // the binary record. Therefore we convert <> to =. + if token == "blanks" { + if operator == 5 { + token = " " + } + } else { + if operator == 5 { + operator = 2 + token = "blanks" + } else { + operator = 5 + token = " " + } + } + } + // if the string token contains an Excel match character then change the + // operator type to indicate a non "simple" equality. + re, _ = regexp.Match("[*?]", []byte(token)) + if operator == 2 && re { + operator = 22 + } + return []int{operator}, token, nil +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/templates.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/templates.go new file mode 100644 index 0000000000..17fc8d4011 --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/templates.go @@ -0,0 +1,40 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. +// +// This file contains default templates for XML files we don't yet populated +// based on content. + +package excelize + +// XMLHeader define an XML declaration can also contain a standalone declaration. +const XMLHeader = "\n" + +var ( + // XMLHeaderByte define an XML declaration can also contain a standalone + // declaration. + XMLHeaderByte = []byte(XMLHeader) +) + +const templateDocpropsApp = `0Go Excelize` + +const templateContentTypes = `` + +const templateWorkbook = `` + +const templateStyles = `` + +const templateSheet = `` + +const templateWorkbookRels = `` + +const templateDocpropsCore = `xuri2006-09-16T00:00:00Z2006-09-16T00:00:00Z` + +const templateRels = `` + +const templateTheme = `` diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/vmlDrawing.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/vmlDrawing.go new file mode 100644 index 0000000000..8b1d00fe96 --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/vmlDrawing.go @@ -0,0 +1,144 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. + +package excelize + +import "encoding/xml" + +// vmlDrawing directly maps the root element in the file +// xl/drawings/vmlDrawing%d.vml. +type vmlDrawing struct { + XMLName xml.Name `xml:"xml"` + XMLNSv string `xml:"xmlns:v,attr"` + XMLNSo string `xml:"xmlns:o,attr"` + XMLNSx string `xml:"xmlns:x,attr"` + XMLNSmv string `xml:"xmlns:mv,attr"` + Shapelayout *xlsxShapelayout `xml:"o:shapelayout"` + Shapetype *xlsxShapetype `xml:"v:shapetype"` + Shape []xlsxShape `xml:"v:shape"` +} + +// xlsxShapelayout directly maps the shapelayout element. This element contains +// child elements that store information used in the editing and layout of +// shapes. +type xlsxShapelayout struct { + Ext string `xml:"v:ext,attr"` + IDmap *xlsxIDmap `xml:"o:idmap"` +} + +// xlsxIDmap directly maps the idmap element. +type xlsxIDmap struct { + Ext string `xml:"v:ext,attr"` + Data int `xml:"data,attr"` +} + +// xlsxShape directly maps the shape element. +type xlsxShape struct { + XMLName xml.Name `xml:"v:shape"` + ID string `xml:"id,attr"` + Type string `xml:"type,attr"` + Style string `xml:"style,attr"` + Fillcolor string `xml:"fillcolor,attr"` + Insetmode string `xml:"urn:schemas-microsoft-com:office:office insetmode,attr,omitempty"` + Strokecolor string `xml:"strokecolor,attr,omitempty"` + Val string `xml:",innerxml"` +} + +// xlsxShapetype directly maps the shapetype element. +type xlsxShapetype struct { + ID string `xml:"id,attr"` + Coordsize string `xml:"coordsize,attr"` + Spt int `xml:"o:spt,attr"` + Path string `xml:"path,attr"` + Stroke *xlsxStroke `xml:"v:stroke"` + VPath *vPath `xml:"v:path"` +} + +// xlsxStroke directly maps the stroke element. +type xlsxStroke struct { + Joinstyle string `xml:"joinstyle,attr"` +} + +// vPath directly maps the v:path element. +type vPath struct { + Gradientshapeok string `xml:"gradientshapeok,attr,omitempty"` + Connecttype string `xml:"o:connecttype,attr"` +} + +// vFill directly maps the v:fill element. This element must be defined within a +// Shape element. +type vFill struct { + Angle int `xml:"angle,attr,omitempty"` + Color2 string `xml:"color2,attr"` + Type string `xml:"type,attr,omitempty"` + Fill *oFill `xml:"o:fill"` +} + +// oFill directly maps the o:fill element. +type oFill struct { + Ext string `xml:"v:ext,attr"` + Type string `xml:"type,attr,omitempty"` +} + +// vShadow directly maps the v:shadow element. This element must be defined +// within a Shape element. In addition, the On attribute must be set to True. +type vShadow struct { + On string `xml:"on,attr"` + Color string `xml:"color,attr,omitempty"` + Obscured string `xml:"obscured,attr"` +} + +// vTextbox directly maps the v:textbox element. This element must be defined +// within a Shape element. +type vTextbox struct { + Style string `xml:"style,attr"` + Div *xlsxDiv `xml:"div"` +} + +// xlsxDiv directly maps the div element. +type xlsxDiv struct { + Style string `xml:"style,attr"` +} + +// xClientData (Attached Object Data) directly maps the x:ClientData element. +// This element specifies data associated with objects attached to a +// spreadsheet. While this element might contain any of the child elements +// below, only certain combinations are meaningful. The ObjectType attribute +// determines the kind of object the element represents and which subset of +// child elements is appropriate. Relevant groups are identified for each child +// element. +type xClientData struct { + ObjectType string `xml:"ObjectType,attr"` + MoveWithCells string `xml:"x:MoveWithCells,omitempty"` + SizeWithCells string `xml:"x:SizeWithCells,omitempty"` + Anchor string `xml:"x:Anchor"` + AutoFill string `xml:"x:AutoFill"` + Row int `xml:"x:Row"` + Column int `xml:"x:Column"` +} + +// decodeVmlDrawing defines the structure used to parse the file +// xl/drawings/vmlDrawing%d.vml. +type decodeVmlDrawing struct { + Shape []decodeShape `xml:"urn:schemas-microsoft-com:vml shape"` +} + +// decodeShape defines the structure used to parse the particular shape element. +type decodeShape struct { + Val string `xml:",innerxml"` +} + +// encodeShape defines the structure used to re-serialization shape element. +type encodeShape struct { + Fill *vFill `xml:"v:fill"` + Shadow *vShadow `xml:"v:shadow"` + Path *vPath `xml:"v:path"` + Textbox *vTextbox `xml:"v:textbox"` + ClientData *xClientData `xml:"x:ClientData"` +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlChart.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlChart.go new file mode 100644 index 0000000000..163812d542 --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlChart.go @@ -0,0 +1,623 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. + +package excelize + +import "encoding/xml" + +// xlsxChartSpace directly maps the c:chartSpace element. The chart namespace in +// DrawingML is for representing visualizations of numeric data with column +// charts, pie charts, scatter charts, or other types of charts. +type xlsxChartSpace struct { + XMLName xml.Name `xml:"c:chartSpace"` + XMLNSc string `xml:"xmlns:c,attr"` + XMLNSa string `xml:"xmlns:a,attr"` + XMLNSr string `xml:"xmlns:r,attr"` + XMLNSc16r2 string `xml:"xmlns:c16r2,attr"` + Date1904 *attrValBool `xml:"c:date1904"` + Lang *attrValString `xml:"c:lang"` + RoundedCorners *attrValBool `xml:"c:roundedCorners"` + Chart cChart `xml:"c:chart"` + SpPr *cSpPr `xml:"c:spPr"` + TxPr *cTxPr `xml:"c:txPr"` + PrintSettings *cPrintSettings `xml:"c:printSettings"` +} + +// cThicknessSpPr directly maps the element that specifies the thickness of the +// walls or floor as a percentage of the largest dimension of the plot volume +// and SpPr element. +type cThicknessSpPr struct { + Thickness *attrValInt `xml:"c:thickness"` + SpPr *cSpPr `xml:"c:spPr"` +} + +// cChart (Chart) directly maps the c:chart element. This element specifies a +// title. +type cChart struct { + Title *cTitle `xml:"c:title"` + AutoTitleDeleted *cAutoTitleDeleted `xml:"c:autoTitleDeleted"` + View3D *cView3D `xml:"c:view3D"` + Floor *cThicknessSpPr `xml:"c:floor"` + SideWall *cThicknessSpPr `xml:"c:sideWall"` + BackWall *cThicknessSpPr `xml:"c:backWall"` + PlotArea *cPlotArea `xml:"c:plotArea"` + Legend *cLegend `xml:"c:legend"` + PlotVisOnly *attrValBool `xml:"c:plotVisOnly"` + DispBlanksAs *attrValString `xml:"c:dispBlanksAs"` + ShowDLblsOverMax *attrValBool `xml:"c:showDLblsOverMax"` +} + +// cTitle (Title) directly maps the c:title element. This element specifies a +// title. +type cTitle struct { + Tx cTx `xml:"c:tx,omitempty"` + Layout string `xml:"c:layout,omitempty"` + Overlay attrValBool `xml:"c:overlay,omitempty"` + SpPr cSpPr `xml:"c:spPr,omitempty"` + TxPr cTxPr `xml:"c:txPr,omitempty"` +} + +// cTx (Chart Text) directly maps the c:tx element. This element specifies text +// to use on a chart, including rich text formatting. +type cTx struct { + StrRef *cStrRef `xml:"c:strRef"` + Rich *cRich `xml:"c:rich,omitempty"` +} + +// cRich (Rich Text) directly maps the c:rich element. This element contains a +// string with rich text formatting. +type cRich struct { + BodyPr aBodyPr `xml:"a:bodyPr,omitempty"` + LstStyle string `xml:"a:lstStyle,omitempty"` + P aP `xml:"a:p"` +} + +// aBodyPr (Body Properties) directly maps the a:bodyPr element. This element +// defines the body properties for the text body within a shape. +type aBodyPr struct { + Anchor string `xml:"anchor,attr,omitempty"` + AnchorCtr bool `xml:"anchorCtr,attr"` + Rot int `xml:"rot,attr"` + BIns float64 `xml:"bIns,attr,omitempty"` + CompatLnSpc bool `xml:"compatLnSpc,attr,omitempty"` + ForceAA bool `xml:"forceAA,attr,omitempty"` + FromWordArt bool `xml:"fromWordArt,attr,omitempty"` + HorzOverflow string `xml:"horzOverflow,attr,omitempty"` + LIns float64 `xml:"lIns,attr,omitempty"` + NumCol int `xml:"numCol,attr,omitempty"` + RIns float64 `xml:"rIns,attr,omitempty"` + RtlCol bool `xml:"rtlCol,attr,omitempty"` + SpcCol int `xml:"spcCol,attr,omitempty"` + SpcFirstLastPara bool `xml:"spcFirstLastPara,attr"` + TIns float64 `xml:"tIns,attr,omitempty"` + Upright bool `xml:"upright,attr,omitempty"` + Vert string `xml:"vert,attr,omitempty"` + VertOverflow string `xml:"vertOverflow,attr,omitempty"` + Wrap string `xml:"wrap,attr,omitempty"` +} + +// aP (Paragraph) directly maps the a:p element. This element specifies a +// paragraph of content in the document. +type aP struct { + PPr *aPPr `xml:"a:pPr"` + R *aR `xml:"a:r"` + EndParaRPr *aEndParaRPr `xml:"a:endParaRPr"` +} + +// aPPr (Paragraph Properties) directly maps the a:pPr element. This element +// specifies a set of paragraph properties which shall be applied to the +// contents of the parent paragraph after all style/numbering/table properties +// have been applied to the text. These properties are defined as direct +// formatting, since they are directly applied to the paragraph and supersede +// any formatting from styles. +type aPPr struct { + DefRPr aRPr `xml:"a:defRPr"` +} + +// aSolidFill (Solid Fill) directly maps the solidFill element. This element +// specifies a solid color fill. The shape is filled entirely with the specified +// color. +type aSolidFill struct { + SchemeClr *aSchemeClr `xml:"a:schemeClr"` + SrgbClr *attrValString `xml:"a:srgbClr"` +} + +// aSchemeClr (Scheme Color) directly maps the a:schemeClr element. This +// element specifies a color bound to a user's theme. As with all elements which +// define a color, it is possible to apply a list of color transforms to the +// base color defined. +type aSchemeClr struct { + Val string `xml:"val,attr,omitempty"` + LumMod *attrValInt `xml:"a:lumMod"` + LumOff *attrValInt `xml:"a:lumOff"` +} + +// attrValInt directly maps the val element with integer data type as an +// attribute。 +type attrValInt struct { + Val int `xml:"val,attr"` +} + +// attrValFloat directly maps the val element with float64 data type as an +// attribute。 +type attrValFloat struct { + Val float64 `xml:"val,attr"` +} + +// attrValBool directly maps the val element with boolean data type as an +// attribute。 +type attrValBool struct { + Val bool `xml:"val,attr"` +} + +// attrValString directly maps the val element with string data type as an +// attribute。 +type attrValString struct { + Val string `xml:"val,attr"` +} + +// aCs directly maps the a:cs element. +type aCs struct { + Typeface string `xml:"typeface,attr"` +} + +// aEa directly maps the a:ea element. +type aEa struct { + Typeface string `xml:"typeface,attr"` +} + +// aLatin (Latin Font) directly maps the a:latin element. This element +// specifies that a Latin font be used for a specific run of text. This font is +// specified with a typeface attribute much like the others but is specifically +// classified as a Latin font. +type aLatin struct { + Typeface string `xml:"typeface,attr"` +} + +// aR directly maps the a:r element. +type aR struct { + RPr aRPr `xml:"a:rPr,omitempty"` + T string `xml:"a:t,omitempty"` +} + +// aRPr (Run Properties) directly maps the c:rPr element. This element +// specifies a set of run properties which shall be applied to the contents of +// the parent run after all style formatting has been applied to the text. These +// properties are defined as direct formatting, since they are directly applied +// to the run and supersede any formatting from styles. +type aRPr struct { + AltLang string `xml:"altLang,attr,omitempty"` + B bool `xml:"b,attr"` + Baseline int `xml:"baseline,attr"` + Bmk string `xml:"bmk,attr,omitempty"` + Cap string `xml:"cap,attr,omitempty"` + Dirty bool `xml:"dirty,attr,omitempty"` + Err bool `xml:"err,attr,omitempty"` + I bool `xml:"i,attr"` + Kern int `xml:"kern,attr"` + Kumimoji bool `xml:"kumimoji,attr,omitempty"` + Lang string `xml:"lang,attr,omitempty"` + NoProof bool `xml:"noProof,attr,omitempty"` + NormalizeH bool `xml:"normalizeH,attr,omitempty"` + SmtClean bool `xml:"smtClean,attr,omitempty"` + SmtID uint64 `xml:"smtId,attr,omitempty"` + Spc int `xml:"spc,attr"` + Strike string `xml:"strike,attr,omitempty"` + Sz int `xml:"sz,attr,omitempty"` + U string `xml:"u,attr,omitempty"` + SolidFill *aSolidFill `xml:"a:solidFill"` + Latin *aLatin `xml:"a:latin"` + Ea *aEa `xml:"a:ea"` + Cs *aCs `xml:"a:cs"` +} + +// cSpPr (Shape Properties) directly maps the c:spPr element. This element +// specifies the visual shape properties that can be applied to a shape. These +// properties include the shape fill, outline, geometry, effects, and 3D +// orientation. +type cSpPr struct { + NoFill *string `xml:"a:noFill"` + SolidFill *aSolidFill `xml:"a:solidFill"` + Ln *aLn `xml:"a:ln"` + Sp3D *aSp3D `xml:"a:sp3d"` + EffectLst *string `xml:"a:effectLst"` +} + +// aSp3D (3-D Shape Properties) directly maps the a:sp3d element. This element +// defines the 3D properties associated with a particular shape in DrawingML. +// The 3D properties which can be applied to a shape are top and bottom bevels, +// a contour and an extrusion. +type aSp3D struct { + ContourW int `xml:"contourW,attr"` + ContourClr *aContourClr `xml:"a:contourClr"` +} + +// aContourClr (Contour Color) directly maps the a:contourClr element. This +// element defines the color for the contour on a shape. The contour of a shape +// is a solid filled line which surrounds the outer edges of the shape. +type aContourClr struct { + SchemeClr *aSchemeClr `xml:"a:schemeClr"` +} + +// aLn (Outline) directly maps the a:ln element. This element specifies an +// outline style that can be applied to a number of different objects such as +// shapes and text. The line allows for the specifying of many different types +// of outlines including even line dashes and bevels. +type aLn struct { + Algn string `xml:"algn,attr,omitempty"` + Cap string `xml:"cap,attr,omitempty"` + Cmpd string `xml:"cmpd,attr,omitempty"` + W int `xml:"w,attr,omitempty"` + NoFill string `xml:"a:noFill,omitempty"` + Round string `xml:"a:round,omitempty"` + SolidFill *aSolidFill `xml:"a:solidFill"` +} + +// cTxPr (Text Properties) directly maps the c:txPr element. This element +// specifies text formatting. The lstStyle element is not supported. +type cTxPr struct { + BodyPr aBodyPr `xml:"a:bodyPr,omitempty"` + LstStyle string `xml:"a:lstStyle,omitempty"` + P aP `xml:"a:p,omitempty"` +} + +// aEndParaRPr (End Paragraph Run Properties) directly maps the a:endParaRPr +// element. This element specifies the text run properties that are to be used +// if another run is inserted after the last run specified. This effectively +// saves the run property state so that it can be applied when the user enters +// additional text. If this element is omitted, then the application can +// determine which default properties to apply. It is recommended that this +// element be specified at the end of the list of text runs within the paragraph +// so that an orderly list is maintained. +type aEndParaRPr struct { + Lang string `xml:"lang,attr"` + AltLang string `xml:"altLang,attr,omitempty"` + Sz int `xml:"sz,attr,omitempty"` +} + +// cAutoTitleDeleted (Auto Title Is Deleted) directly maps the +// c:autoTitleDeleted element. This element specifies the title shall not be +// shown for this chart. +type cAutoTitleDeleted struct { + Val bool `xml:"val,attr"` +} + +// cView3D (View In 3D) directly maps the c:view3D element. This element +// specifies the 3-D view of the chart. +type cView3D struct { + RotX *attrValInt `xml:"c:rotX"` + RotY *attrValInt `xml:"c:rotY"` + DepthPercent *attrValInt `xml:"c:depthPercent"` + RAngAx *attrValInt `xml:"c:rAngAx"` +} + +// cPlotArea directly maps the c:plotArea element. This element specifies the +// plot area of the chart. +type cPlotArea struct { + Layout *string `xml:"c:layout"` + AreaChart *cCharts `xml:"c:areaChart"` + Area3DChart *cCharts `xml:"c:area3DChart"` + BarChart *cCharts `xml:"c:barChart"` + Bar3DChart *cCharts `xml:"c:bar3DChart"` + DoughnutChart *cCharts `xml:"c:doughnutChart"` + LineChart *cCharts `xml:"c:lineChart"` + PieChart *cCharts `xml:"c:pieChart"` + Pie3DChart *cCharts `xml:"c:pie3DChart"` + RadarChart *cCharts `xml:"c:radarChart"` + ScatterChart *cCharts `xml:"c:scatterChart"` + CatAx []*cAxs `xml:"c:catAx"` + ValAx []*cAxs `xml:"c:valAx"` + SpPr *cSpPr `xml:"c:spPr"` +} + +// cCharts specifies the common element of the chart. +type cCharts struct { + BarDir *attrValString `xml:"c:barDir"` + Grouping *attrValString `xml:"c:grouping"` + RadarStyle *attrValString `xml:"c:radarStyle"` + ScatterStyle *attrValString `xml:"c:scatterStyle"` + VaryColors *attrValBool `xml:"c:varyColors"` + Ser *[]cSer `xml:"c:ser"` + DLbls *cDLbls `xml:"c:dLbls"` + HoleSize *attrValInt `xml:"c:holeSize"` + Smooth *attrValBool `xml:"c:smooth"` + Overlap *attrValInt `xml:"c:overlap"` + AxID []*attrValInt `xml:"c:axId"` +} + +// cAxs directly maps the c:catAx and c:valAx element. +type cAxs struct { + AxID *attrValInt `xml:"c:axId"` + Scaling *cScaling `xml:"c:scaling"` + Delete *attrValBool `xml:"c:delete"` + AxPos *attrValString `xml:"c:axPos"` + NumFmt *cNumFmt `xml:"c:numFmt"` + MajorTickMark *attrValString `xml:"c:majorTickMark"` + MinorTickMark *attrValString `xml:"c:minorTickMark"` + TickLblPos *attrValString `xml:"c:tickLblPos"` + SpPr *cSpPr `xml:"c:spPr"` + TxPr *cTxPr `xml:"c:txPr"` + CrossAx *attrValInt `xml:"c:crossAx"` + Crosses *attrValString `xml:"c:crosses"` + CrossBetween *attrValString `xml:"c:crossBetween"` + Auto *attrValBool `xml:"c:auto"` + LblAlgn *attrValString `xml:"c:lblAlgn"` + LblOffset *attrValInt `xml:"c:lblOffset"` + NoMultiLvlLbl *attrValBool `xml:"c:noMultiLvlLbl"` +} + +// cScaling directly maps the c:scaling element. This element contains +// additional axis settings. +type cScaling struct { + Orientation *attrValString `xml:"c:orientation"` + Max *attrValFloat `xml:"c:max"` + Min *attrValFloat `xml:"c:min"` +} + +// cNumFmt (Numbering Format) directly maps the c:numFmt element. This element +// specifies number formatting for the parent element. +type cNumFmt struct { + FormatCode string `xml:"formatCode,attr"` + SourceLinked bool `xml:"sourceLinked,attr"` +} + +// cSer directly maps the c:ser element. This element specifies a series on a +// chart. +type cSer struct { + IDx *attrValInt `xml:"c:idx"` + Order *attrValInt `xml:"c:order"` + Tx *cTx `xml:"c:tx"` + SpPr *cSpPr `xml:"c:spPr"` + DPt []*cDPt `xml:"c:dPt"` + DLbls *cDLbls `xml:"c:dLbls"` + Marker *cMarker `xml:"c:marker"` + InvertIfNegative *attrValBool `xml:"c:invertIfNegative"` + Cat *cCat `xml:"c:cat"` + Val *cVal `xml:"c:val"` + XVal *cCat `xml:"c:xVal"` + YVal *cVal `xml:"c:yVal"` + Smooth *attrValBool `xml:"c:smooth"` +} + +// cMarker (Marker) directly maps the c:marker element. This element specifies a +// data marker. +type cMarker struct { + Symbol *attrValString `xml:"c:symbol"` + Size *attrValInt `xml:"c:size"` + SpPr *cSpPr `xml:"c:spPr"` +} + +// cDPt (Data Point) directly maps the c:dPt element. This element specifies a +// single data point. +type cDPt struct { + IDx *attrValInt `xml:"c:idx"` + Bubble3D *attrValBool `xml:"c:bubble3D"` + SpPr *cSpPr `xml:"c:spPr"` +} + +// cCat (Category Axis Data) directly maps the c:cat element. This element +// specifies the data used for the category axis. +type cCat struct { + StrRef *cStrRef `xml:"c:strRef"` +} + +// cStrRef (String Reference) directly maps the c:strRef element. This element +// specifies a reference to data for a single data label or title with a cache +// of the last values used. +type cStrRef struct { + F string `xml:"c:f"` + StrCache *cStrCache `xml:"c:strCache"` +} + +// cStrCache (String Cache) directly maps the c:strCache element. This element +// specifies the last string data used for a chart. +type cStrCache struct { + Pt []*cPt `xml:"c:pt"` + PtCount *attrValInt `xml:"c:ptCount"` +} + +// cPt directly maps the c:pt element. This element specifies data for a +// particular data point. +type cPt struct { + IDx int `xml:"idx,attr"` + V *string `xml:"c:v"` +} + +// cVal directly maps the c:val element. This element specifies the data values +// which shall be used to define the location of data markers on a chart. +type cVal struct { + NumRef *cNumRef `xml:"c:numRef"` +} + +// cNumRef directly maps the c:numRef element. This element specifies a +// reference to numeric data with a cache of the last values used. +type cNumRef struct { + F string `xml:"c:f"` + NumCache *cNumCache `xml:"c:numCache"` +} + +// cNumCache directly maps the c:numCache element. This element specifies the +// last data shown on the chart for a series. +type cNumCache struct { + FormatCode string `xml:"c:formatCode"` + Pt []*cPt `xml:"c:pt"` + PtCount *attrValInt `xml:"c:ptCount"` +} + +// cDLbls (Data Lables) directly maps the c:dLbls element. This element serves +// as a root element that specifies the settings for the data labels for an +// entire series or the entire chart. It contains child elements that specify +// the specific formatting and positioning settings. +type cDLbls struct { + ShowLegendKey *attrValBool `xml:"c:showLegendKey"` + ShowVal *attrValBool `xml:"c:showVal"` + ShowCatName *attrValBool `xml:"c:showCatName"` + ShowSerName *attrValBool `xml:"c:showSerName"` + ShowPercent *attrValBool `xml:"c:showPercent"` + ShowBubbleSize *attrValBool `xml:"c:showBubbleSize"` + ShowLeaderLines *attrValBool `xml:"c:showLeaderLines"` +} + +// cLegend (Legend) directly maps the c:legend element. This element specifies +// the legend. +type cLegend struct { + Layout *string `xml:"c:layout"` + LegendPos *attrValString `xml:"c:legendPos"` + Overlay *attrValBool `xml:"c:overlay"` + SpPr *cSpPr `xml:"c:spPr"` + TxPr *cTxPr `xml:"c:txPr"` +} + +// cPrintSettings directly maps the c:printSettings element. This element +// specifies the print settings for the chart. +type cPrintSettings struct { + HeaderFooter *string `xml:"c:headerFooter"` + PageMargins *cPageMargins `xml:"c:pageMargins"` + PageSetup *string `xml:"c:pageSetup"` +} + +// cPageMargins directly maps the c:pageMargins element. This element specifies +// the page margins for a chart. +type cPageMargins struct { + B float64 `xml:"b,attr"` + Footer float64 `xml:"footer,attr"` + Header float64 `xml:"header,attr"` + L float64 `xml:"l,attr"` + R float64 `xml:"r,attr"` + T float64 `xml:"t,attr"` +} + +// formatChartAxis directly maps the format settings of the chart axis. +type formatChartAxis struct { + Crossing string `json:"crossing"` + MajorTickMark string `json:"major_tick_mark"` + MinorTickMark string `json:"minor_tick_mark"` + MinorUnitType string `json:"minor_unit_type"` + MajorUnit int `json:"major_unit"` + MajorUnitType string `json:"major_unit_type"` + DisplayUnits string `json:"display_units"` + DisplayUnitsVisible bool `json:"display_units_visible"` + DateAxis bool `json:"date_axis"` + ReverseOrder bool `json:"reverse_order"` + Maximum float64 `json:"maximum"` + Minimum float64 `json:"minimum"` + NumFormat string `json:"num_format"` + NumFont struct { + Color string `json:"color"` + Bold bool `json:"bold"` + Italic bool `json:"italic"` + Underline bool `json:"underline"` + } `json:"num_font"` + NameLayout formatLayout `json:"name_layout"` +} + +type formatChartDimension struct { + Width int `json:"width"` + Height int `json:"height"` +} + +// formatChart directly maps the format settings of the chart. +type formatChart struct { + Type string `json:"type"` + Series []formatChartSeries `json:"series"` + Format formatPicture `json:"format"` + Dimension formatChartDimension `json:"dimension"` + Legend formatChartLegend `json:"legend"` + Title formatChartTitle `json:"title"` + XAxis formatChartAxis `json:"x_axis"` + YAxis formatChartAxis `json:"y_axis"` + Chartarea struct { + Border struct { + None bool `json:"none"` + } `json:"border"` + Fill struct { + Color string `json:"color"` + } `json:"fill"` + Pattern struct { + Pattern string `json:"pattern"` + FgColor string `json:"fg_color"` + BgColor string `json:"bg_color"` + } `json:"pattern"` + } `json:"chartarea"` + Plotarea struct { + ShowBubbleSize bool `json:"show_bubble_size"` + ShowCatName bool `json:"show_cat_name"` + ShowLeaderLines bool `json:"show_leader_lines"` + ShowPercent bool `json:"show_percent"` + ShowSerName bool `json:"show_series_name"` + ShowVal bool `json:"show_val"` + Gradient struct { + Colors []string `json:"colors"` + } `json:"gradient"` + Border struct { + Color string `json:"color"` + Width int `json:"width"` + DashType string `json:"dash_type"` + } `json:"border"` + Fill struct { + Color string `json:"color"` + } `json:"fill"` + Layout formatLayout `json:"layout"` + } `json:"plotarea"` + ShowBlanksAs string `json:"show_blanks_as"` + ShowHiddenData bool `json:"show_hidden_data"` + SetRotation int `json:"set_rotation"` + SetHoleSize int `json:"set_hole_size"` +} + +// formatChartLegend directly maps the format settings of the chart legend. +type formatChartLegend struct { + None bool `json:"none"` + DeleteSeries []int `json:"delete_series"` + Font formatFont `json:"font"` + Layout formatLayout `json:"layout"` + Position string `json:"position"` + ShowLegendEntry bool `json:"show_legend_entry"` + ShowLegendKey bool `json:"show_legend_key"` +} + +// formatChartSeries directly maps the format settings of the chart series. +type formatChartSeries struct { + Name string `json:"name"` + Categories string `json:"categories"` + Values string `json:"values"` + Line struct { + None bool `json:"none"` + Color string `json:"color"` + } `json:"line"` + Marker struct { + Type string `json:"type"` + Size int `json:"size"` + Width float64 `json:"width"` + Border struct { + Color string `json:"color"` + None bool `json:"none"` + } `json:"border"` + Fill struct { + Color string `json:"color"` + None bool `json:"none"` + } `json:"fill"` + } `json:"marker"` +} + +// formatChartTitle directly maps the format settings of the chart title. +type formatChartTitle struct { + None bool `json:"none"` + Name string `json:"name"` + Overlay bool `json:"overlay"` + Layout formatLayout `json:"layout"` +} + +// formatLayout directly maps the format settings of the element layout. +type formatLayout struct { + X float64 `json:"x"` + Y float64 `json:"y"` + Width float64 `json:"width"` + Height float64 `json:"height"` +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlComments.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlComments.go new file mode 100644 index 0000000000..5ffbecf740 --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlComments.go @@ -0,0 +1,72 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. + +package excelize + +import "encoding/xml" + +// xlsxComments directly maps the comments element from the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main. A comment is a +// rich text note that is attached to and associated with a cell, separate from +// other cell content. Comment content is stored separate from the cell, and is +// displayed in a drawing object (like a text box) that is separate from, but +// associated with, a cell. Comments are used as reminders, such as noting how a +// complex formula works, or to provide feedback to other users. Comments can +// also be used to explain assumptions made in a formula or to call out +// something special about the cell. +type xlsxComments struct { + XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main comments"` + Authors []xlsxAuthor `xml:"authors"` + CommentList xlsxCommentList `xml:"commentList"` +} + +// xlsxAuthor directly maps the author element. This element holds a string +// representing the name of a single author of comments. Every comment shall +// have an author. The maximum length of the author string is an implementation +// detail, but a good guideline is 255 chars. +type xlsxAuthor struct { + Author string `xml:"author"` +} + +// xlsxCommentList (List of Comments) directly maps the xlsxCommentList element. +// This element is a container that holds a list of comments for the sheet. +type xlsxCommentList struct { + Comment []xlsxComment `xml:"comment"` +} + +// xlsxComment directly maps the comment element. This element represents a +// single user entered comment. Each comment shall have an author and can +// optionally contain richly formatted text. +type xlsxComment struct { + Ref string `xml:"ref,attr"` + AuthorID int `xml:"authorId,attr"` + Text xlsxText `xml:"text"` +} + +// xlsxText directly maps the text element. This element contains rich text +// which represents the text of a comment. The maximum length for this text is a +// spreadsheet application implementation detail. A recommended guideline is +// 32767 chars. +type xlsxText struct { + R []xlsxR `xml:"r"` +} + +// formatComment directly maps the format settings of the comment. +type formatComment struct { + Author string `json:"author"` + Text string `json:"text"` +} + +// Comment directly maps the comment information. +type Comment struct { + Author string `json:"author"` + AuthorID int `json:"author_id"` + Ref string `json:"ref"` + Text string `json:"text"` +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlContentTypes.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlContentTypes.go new file mode 100644 index 0000000000..e99b0b32d5 --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlContentTypes.go @@ -0,0 +1,35 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. + +package excelize + +import "encoding/xml" + +// xlsxTypes directly maps the types element of content types for relationship +// parts, it takes a Multipurpose Internet Mail Extension (MIME) media type as a +// value. +type xlsxTypes struct { + XMLName xml.Name `xml:"http://schemas.openxmlformats.org/package/2006/content-types Types"` + Overrides []xlsxOverride `xml:"Override"` + Defaults []xlsxDefault `xml:"Default"` +} + +// xlsxOverride directly maps the override element in the namespace +// http://schemas.openxmlformats.org/package/2006/content-types +type xlsxOverride struct { + PartName string `xml:",attr"` + ContentType string `xml:",attr"` +} + +// xlsxDefault directly maps the default element in the namespace +// http://schemas.openxmlformats.org/package/2006/content-types +type xlsxDefault struct { + Extension string `xml:",attr"` + ContentType string `xml:",attr"` +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlDecodeDrawing.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlDecodeDrawing.go new file mode 100644 index 0000000000..eead575265 --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlDecodeDrawing.go @@ -0,0 +1,196 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. + +package excelize + +import "encoding/xml" + +// decodeCellAnchor directly maps the oneCellAnchor (One Cell Anchor Shape Size) +// and twoCellAnchor (Two Cell Anchor Shape Size). This element specifies a two +// cell anchor placeholder for a group, a shape, or a drawing element. It moves +// with cells and its extents are in EMU units. +type decodeCellAnchor struct { + EditAs string `xml:"editAs,attr,omitempty"` + Content string `xml:",innerxml"` +} + +// decodeWsDr directly maps the root element for a part of this content type +// shall wsDr. In order to solve the problem that the label structure is changed +// after serialization and deserialization, two different structures are +// defined. decodeWsDr just for deserialization. +type decodeWsDr struct { + A string `xml:"xmlns a,attr"` + Xdr string `xml:"xmlns xdr,attr"` + R string `xml:"xmlns r,attr"` + OneCellAnchor []*decodeCellAnchor `xml:"oneCellAnchor,omitempty"` + TwoCellAnchor []*decodeCellAnchor `xml:"twoCellAnchor,omitempty"` + XMLName xml.Name `xml:"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing wsDr,omitempty"` +} + +// decodeTwoCellAnchor directly maps the oneCellAnchor (One Cell Anchor Shape +// Size) and twoCellAnchor (Two Cell Anchor Shape Size). This element specifies +// a two cell anchor placeholder for a group, a shape, or a drawing element. It +// moves with cells and its extents are in EMU units. +type decodeTwoCellAnchor struct { + From *decodeFrom `xml:"from"` + To *decodeTo `xml:"to"` + Pic *decodePic `xml:"pic,omitempty"` + ClientData *decodeClientData `xml:"clientData"` +} + +// decodeCNvPr directly maps the cNvPr (Non-Visual Drawing Properties). This +// element specifies non-visual canvas properties. This allows for additional +// information that does not affect the appearance of the picture to be stored. +type decodeCNvPr struct { + ID int `xml:"id,attr"` + Name string `xml:"name,attr"` + Descr string `xml:"descr,attr"` + Title string `xml:"title,attr,omitempty"` +} + +// decodePicLocks directly maps the picLocks (Picture Locks). This element +// specifies all locking properties for a graphic frame. These properties inform +// the generating application about specific properties that have been +// previously locked and thus should not be changed. +type decodePicLocks struct { + NoAdjustHandles bool `xml:"noAdjustHandles,attr,omitempty"` + NoChangeArrowheads bool `xml:"noChangeArrowheads,attr,omitempty"` + NoChangeAspect bool `xml:"noChangeAspect,attr"` + NoChangeShapeType bool `xml:"noChangeShapeType,attr,omitempty"` + NoCrop bool `xml:"noCrop,attr,omitempty"` + NoEditPoints bool `xml:"noEditPoints,attr,omitempty"` + NoGrp bool `xml:"noGrp,attr,omitempty"` + NoMove bool `xml:"noMove,attr,omitempty"` + NoResize bool `xml:"noResize,attr,omitempty"` + NoRot bool `xml:"noRot,attr,omitempty"` + NoSelect bool `xml:"noSelect,attr,omitempty"` +} + +// decodeBlip directly maps the blip element in the namespace +// http://purl.oclc.org/ooxml/officeDoc ument/relationships - This element +// specifies the existence of an image (binary large image or picture) and +// contains a reference to the image data. +type decodeBlip struct { + Embed string `xml:"embed,attr"` + Cstate string `xml:"cstate,attr,omitempty"` + R string `xml:"r,attr"` +} + +// decodeStretch directly maps the stretch element. This element specifies that +// a BLIP should be stretched to fill the target rectangle. The other option is +// a tile where a BLIP is tiled to fill the available area. +type decodeStretch struct { + FillRect string `xml:"fillRect"` +} + +// decodeOff directly maps the colOff and rowOff element. This element is used +// to specify the column offset within a cell. +type decodeOff struct { + X int `xml:"x,attr"` + Y int `xml:"y,attr"` +} + +// decodeExt directly maps the ext element. +type decodeExt struct { + Cx int `xml:"cx,attr"` + Cy int `xml:"cy,attr"` +} + +// decodePrstGeom directly maps the prstGeom (Preset geometry). This element +// specifies when a preset geometric shape should be used instead of a custom +// geometric shape. The generating application should be able to render all +// preset geometries enumerated in the ST_ShapeType list. +type decodePrstGeom struct { + Prst string `xml:"prst,attr"` +} + +// decodeXfrm directly maps the xfrm (2D Transform for Graphic Frame). This +// element specifies the transform to be applied to the corresponding graphic +// frame. This transformation is applied to the graphic frame just as it would +// be for a shape or group shape. +type decodeXfrm struct { + Off decodeOff `xml:"off"` + Ext decodeExt `xml:"ext"` +} + +// decodeCNvPicPr directly maps the cNvPicPr (Non-Visual Picture Drawing +// Properties). This element specifies the non-visual properties for the picture +// canvas. These properties are to be used by the generating application to +// determine how certain properties are to be changed for the picture object in +// question. +type decodeCNvPicPr struct { + PicLocks decodePicLocks `xml:"picLocks"` +} + +// directly maps the nvPicPr (Non-Visual Properties for a Picture). This element +// specifies all non-visual properties for a picture. This element is a +// container for the non-visual identification properties, shape properties and +// application properties that are to be associated with a picture. This allows +// for additional information that does not affect the appearance of the picture +// to be stored. +type decodeNvPicPr struct { + CNvPr decodeCNvPr `xml:"cNvPr"` + CNvPicPr decodeCNvPicPr `xml:"cNvPicPr"` +} + +// decodeBlipFill directly maps the blipFill (Picture Fill). This element +// specifies the kind of picture fill that the picture object has. Because a +// picture has a picture fill already by default, it is possible to have two +// fills specified for a picture object. +type decodeBlipFill struct { + Blip decodeBlip `xml:"blip"` + Stretch decodeStretch `xml:"stretch"` +} + +// decodeSpPr directly maps the spPr (Shape Properties). This element specifies +// the visual shape properties that can be applied to a picture. These are the +// same properties that are allowed to describe the visual properties of a shape +// but are used here to describe the visual appearance of a picture within a +// document. +type decodeSpPr struct { + Xfrm decodeXfrm `xml:"a:xfrm"` + PrstGeom decodePrstGeom `xml:"a:prstGeom"` +} + +// decodePic elements encompass the definition of pictures within the DrawingML +// framework. While pictures are in many ways very similar to shapes they have +// specific properties that are unique in order to optimize for picture- +// specific scenarios. +type decodePic struct { + NvPicPr decodeNvPicPr `xml:"nvPicPr"` + BlipFill decodeBlipFill `xml:"blipFill"` + SpPr decodeSpPr `xml:"spPr"` +} + +// decodeFrom specifies the starting anchor. +type decodeFrom struct { + Col int `xml:"col"` + ColOff int `xml:"colOff"` + Row int `xml:"row"` + RowOff int `xml:"rowOff"` +} + +// decodeTo directly specifies the ending anchor. +type decodeTo struct { + Col int `xml:"col"` + ColOff int `xml:"colOff"` + Row int `xml:"row"` + RowOff int `xml:"rowOff"` +} + +// decodeClientData directly maps the clientData element. An empty element which +// specifies (via attributes) certain properties related to printing and +// selection of the drawing object. The fLocksWithSheet attribute (either true +// or false) determines whether to disable selection when the sheet is +// protected, and fPrintsWithSheet attribute (either true or false) determines +// whether the object is printed when the sheet is printed. +type decodeClientData struct { + FLocksWithSheet bool `xml:"fLocksWithSheet,attr"` + FPrintsWithSheet bool `xml:"fPrintsWithSheet,attr"` +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlDrawing.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlDrawing.go new file mode 100644 index 0000000000..89496c413f --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlDrawing.go @@ -0,0 +1,402 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. + +package excelize + +import "encoding/xml" + +// Source relationship and namespace. +const ( + SourceRelationship = "http://schemas.openxmlformats.org/officeDocument/2006/relationships" + SourceRelationshipChart = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart" + SourceRelationshipComments = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments" + SourceRelationshipImage = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" + SourceRelationshipTable = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/table" + SourceRelationshipDrawingML = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing" + SourceRelationshipDrawingVML = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing" + SourceRelationshipHyperLink = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" + SourceRelationshipWorkSheet = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" + SourceRelationshipChart201506 = "http://schemas.microsoft.com/office/drawing/2015/06/chart" + SourceRelationshipChart20070802 = "http://schemas.microsoft.com/office/drawing/2007/8/2/chart" + SourceRelationshipChart2014 = "http://schemas.microsoft.com/office/drawing/2014/chart" + SourceRelationshipCompatibility = "http://schemas.openxmlformats.org/markup-compatibility/2006" + NameSpaceDrawingML = "http://schemas.openxmlformats.org/drawingml/2006/main" + NameSpaceDrawingMLChart = "http://schemas.openxmlformats.org/drawingml/2006/chart" + NameSpaceDrawingMLSpreadSheet = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing" + NameSpaceSpreadSheet = "http://schemas.openxmlformats.org/spreadsheetml/2006/main" + NameSpaceXML = "http://www.w3.org/XML/1998/namespace" + StrictSourceRelationship = "http://purl.oclc.org/ooxml/officeDocument/relationships" + StrictSourceRelationshipChart = "http://purl.oclc.org/ooxml/officeDocument/relationships/chart" + StrictSourceRelationshipComments = "http://purl.oclc.org/ooxml/officeDocument/relationships/comments" + StrictSourceRelationshipImage = "http://purl.oclc.org/ooxml/officeDocument/relationships/image" + StrictNameSpaceSpreadSheet = "http://purl.oclc.org/ooxml/spreadsheetml/main" +) + +var supportImageTypes = map[string]string{".gif": ".gif", ".jpg": ".jpeg", ".jpeg": ".jpeg", ".png": ".png"} + +// xlsxCNvPr directly maps the cNvPr (Non-Visual Drawing Properties). This +// element specifies non-visual canvas properties. This allows for additional +// information that does not affect the appearance of the picture to be stored. +type xlsxCNvPr struct { + ID int `xml:"id,attr"` + Name string `xml:"name,attr"` + Descr string `xml:"descr,attr"` + Title string `xml:"title,attr,omitempty"` + HlinkClick *xlsxHlinkClick `xml:"a:hlinkClick"` +} + +// xlsxHlinkClick (Click Hyperlink) Specifies the on-click hyperlink +// information to be applied to a run of text. When the hyperlink text is +// clicked the link is fetched. +type xlsxHlinkClick struct { + R string `xml:"xmlns:r,attr,omitempty"` + RID string `xml:"r:id,attr,omitempty"` + InvalidURL string `xml:"invalidUrl,attr,omitempty"` + Action string `xml:"action,attr,omitempty"` + TgtFrame string `xml:"tgtFrame,attr,omitempty"` + Tooltip string `xml:"tooltip,attr,omitempty"` + History bool `xml:"history,attr,omitempty"` + HighlightClick bool `xml:"highlightClick,attr,omitempty"` + EndSnd bool `xml:"endSnd,attr,omitempty"` +} + +// xlsxPicLocks directly maps the picLocks (Picture Locks). This element +// specifies all locking properties for a graphic frame. These properties inform +// the generating application about specific properties that have been +// previously locked and thus should not be changed. +type xlsxPicLocks struct { + NoAdjustHandles bool `xml:"noAdjustHandles,attr,omitempty"` + NoChangeArrowheads bool `xml:"noChangeArrowheads,attr,omitempty"` + NoChangeAspect bool `xml:"noChangeAspect,attr"` + NoChangeShapeType bool `xml:"noChangeShapeType,attr,omitempty"` + NoCrop bool `xml:"noCrop,attr,omitempty"` + NoEditPoints bool `xml:"noEditPoints,attr,omitempty"` + NoGrp bool `xml:"noGrp,attr,omitempty"` + NoMove bool `xml:"noMove,attr,omitempty"` + NoResize bool `xml:"noResize,attr,omitempty"` + NoRot bool `xml:"noRot,attr,omitempty"` + NoSelect bool `xml:"noSelect,attr,omitempty"` +} + +// xlsxBlip directly maps the blip element in the namespace +// http://purl.oclc.org/ooxml/officeDoc ument/relationships - This element +// specifies the existence of an image (binary large image or picture) and +// contains a reference to the image data. +type xlsxBlip struct { + Embed string `xml:"r:embed,attr"` + Cstate string `xml:"cstate,attr,omitempty"` + R string `xml:"xmlns:r,attr"` +} + +// xlsxStretch directly maps the stretch element. This element specifies that a +// BLIP should be stretched to fill the target rectangle. The other option is a +// tile where a BLIP is tiled to fill the available area. +type xlsxStretch struct { + FillRect string `xml:"a:fillRect"` +} + +// xlsxOff directly maps the colOff and rowOff element. This element is used to +// specify the column offset within a cell. +type xlsxOff struct { + X int `xml:"x,attr"` + Y int `xml:"y,attr"` +} + +// xlsxExt directly maps the ext element. +type xlsxExt struct { + Cx int `xml:"cx,attr"` + Cy int `xml:"cy,attr"` +} + +// xlsxPrstGeom directly maps the prstGeom (Preset geometry). This element +// specifies when a preset geometric shape should be used instead of a custom +// geometric shape. The generating application should be able to render all +// preset geometries enumerated in the ST_ShapeType list. +type xlsxPrstGeom struct { + Prst string `xml:"prst,attr"` +} + +// xlsxXfrm directly maps the xfrm (2D Transform for Graphic Frame). This +// element specifies the transform to be applied to the corresponding graphic +// frame. This transformation is applied to the graphic frame just as it would +// be for a shape or group shape. +type xlsxXfrm struct { + Off xlsxOff `xml:"a:off"` + Ext xlsxExt `xml:"a:ext"` +} + +// xlsxCNvPicPr directly maps the cNvPicPr (Non-Visual Picture Drawing +// Properties). This element specifies the non-visual properties for the picture +// canvas. These properties are to be used by the generating application to +// determine how certain properties are to be changed for the picture object in +// question. +type xlsxCNvPicPr struct { + PicLocks xlsxPicLocks `xml:"a:picLocks"` +} + +// directly maps the nvPicPr (Non-Visual Properties for a Picture). This element +// specifies all non-visual properties for a picture. This element is a +// container for the non-visual identification properties, shape properties and +// application properties that are to be associated with a picture. This allows +// for additional information that does not affect the appearance of the picture +// to be stored. +type xlsxNvPicPr struct { + CNvPr xlsxCNvPr `xml:"xdr:cNvPr"` + CNvPicPr xlsxCNvPicPr `xml:"xdr:cNvPicPr"` +} + +// xlsxBlipFill directly maps the blipFill (Picture Fill). This element +// specifies the kind of picture fill that the picture object has. Because a +// picture has a picture fill already by default, it is possible to have two +// fills specified for a picture object. +type xlsxBlipFill struct { + Blip xlsxBlip `xml:"a:blip"` + Stretch xlsxStretch `xml:"a:stretch"` +} + +// xlsxSpPr directly maps the spPr (Shape Properties). This element specifies +// the visual shape properties that can be applied to a picture. These are the +// same properties that are allowed to describe the visual properties of a shape +// but are used here to describe the visual appearance of a picture within a +// document. +type xlsxSpPr struct { + Xfrm xlsxXfrm `xml:"a:xfrm"` + PrstGeom xlsxPrstGeom `xml:"a:prstGeom"` +} + +// xlsxPic elements encompass the definition of pictures within the DrawingML +// framework. While pictures are in many ways very similar to shapes they have +// specific properties that are unique in order to optimize for picture- +// specific scenarios. +type xlsxPic struct { + NvPicPr xlsxNvPicPr `xml:"xdr:nvPicPr"` + BlipFill xlsxBlipFill `xml:"xdr:blipFill"` + SpPr xlsxSpPr `xml:"xdr:spPr"` +} + +// xlsxFrom specifies the starting anchor. +type xlsxFrom struct { + Col int `xml:"xdr:col"` + ColOff int `xml:"xdr:colOff"` + Row int `xml:"xdr:row"` + RowOff int `xml:"xdr:rowOff"` +} + +// xlsxTo directly specifies the ending anchor. +type xlsxTo struct { + Col int `xml:"xdr:col"` + ColOff int `xml:"xdr:colOff"` + Row int `xml:"xdr:row"` + RowOff int `xml:"xdr:rowOff"` +} + +// xdrClientData directly maps the clientData element. An empty element which +// specifies (via attributes) certain properties related to printing and +// selection of the drawing object. The fLocksWithSheet attribute (either true +// or false) determines whether to disable selection when the sheet is +// protected, and fPrintsWithSheet attribute (either true or false) determines +// whether the object is printed when the sheet is printed. +type xdrClientData struct { + FLocksWithSheet bool `xml:"fLocksWithSheet,attr"` + FPrintsWithSheet bool `xml:"fPrintsWithSheet,attr"` +} + +// xdrCellAnchor directly maps the oneCellAnchor (One Cell Anchor Shape Size) +// and twoCellAnchor (Two Cell Anchor Shape Size). This element specifies a two +// cell anchor placeholder for a group, a shape, or a drawing element. It moves +// with cells and its extents are in EMU units. +type xdrCellAnchor struct { + EditAs string `xml:"editAs,attr,omitempty"` + From *xlsxFrom `xml:"xdr:from"` + To *xlsxTo `xml:"xdr:to"` + Ext *xlsxExt `xml:"xdr:ext"` + Sp *xdrSp `xml:"xdr:sp"` + Pic *xlsxPic `xml:"xdr:pic,omitempty"` + GraphicFrame string `xml:",innerxml"` + ClientData *xdrClientData `xml:"xdr:clientData"` +} + +// xlsxWsDr directly maps the root element for a part of this content type shall +// wsDr. +type xlsxWsDr struct { + XMLName xml.Name `xml:"xdr:wsDr"` + OneCellAnchor []*xdrCellAnchor `xml:"xdr:oneCellAnchor"` + TwoCellAnchor []*xdrCellAnchor `xml:"xdr:twoCellAnchor"` + A string `xml:"xmlns:a,attr,omitempty"` + Xdr string `xml:"xmlns:xdr,attr,omitempty"` + R string `xml:"xmlns:r,attr,omitempty"` +} + +// xlsxGraphicFrame (Graphic Frame) directly maps the xdr:graphicFrame element. +// This element specifies the existence of a graphics frame. This frame contains +// a graphic that was generated by an external source and needs a container in +// which to be displayed on the slide surface. +type xlsxGraphicFrame struct { + XMLName xml.Name `xml:"xdr:graphicFrame"` + Macro string `xml:"macro,attr"` + NvGraphicFramePr xlsxNvGraphicFramePr `xml:"xdr:nvGraphicFramePr"` + Xfrm xlsxXfrm `xml:"xdr:xfrm"` + Graphic *xlsxGraphic `xml:"a:graphic"` +} + +// xlsxNvGraphicFramePr (Non-Visual Properties for a Graphic Frame) directly +// maps the xdr:nvGraphicFramePr element. This element specifies all non-visual +// properties for a graphic frame. This element is a container for the non- +// visual identification properties, shape properties and application properties +// that are to be associated with a graphic frame. This allows for additional +// information that does not affect the appearance of the graphic frame to be +// stored. +type xlsxNvGraphicFramePr struct { + CNvPr *xlsxCNvPr `xml:"xdr:cNvPr"` + ChicNvGraphicFramePr string `xml:"xdr:cNvGraphicFramePr"` +} + +// xlsxGraphic (Graphic Object) directly maps the a:graphic element. This +// element specifies the existence of a single graphic object. Document authors +// should refer to this element when they wish to persist a graphical object of +// some kind. The specification for this graphical object is provided entirely +// by the document author and referenced within the graphicData child element. +type xlsxGraphic struct { + GraphicData *xlsxGraphicData `xml:"a:graphicData"` +} + +// xlsxGraphicData (Graphic Object Data) directly maps the a:graphicData +// element. This element specifies the reference to a graphic object within the +// document. This graphic object is provided entirely by the document authors +// who choose to persist this data within the document. +type xlsxGraphicData struct { + URI string `xml:"uri,attr"` + Chart *xlsxChart `xml:"c:chart,omitempty"` +} + +// xlsxChart (Chart) directly maps the c:chart element. +type xlsxChart struct { + C string `xml:"xmlns:c,attr"` + RID string `xml:"r:id,attr"` + R string `xml:"xmlns:r,attr"` +} + +// xdrSp (Shape) directly maps the xdr:sp element. This element specifies the +// existence of a single shape. A shape can either be a preset or a custom +// geometry, defined using the SpreadsheetDrawingML framework. In addition to a +// geometry each shape can have both visual and non-visual properties attached. +// Text and corresponding styling information can also be attached to a shape. +// This shape is specified along with all other shapes within either the shape +// tree or group shape elements. +type xdrSp struct { + Macro string `xml:"macro,attr"` + Textlink string `xml:"textlink,attr"` + NvSpPr *xdrNvSpPr `xml:"xdr:nvSpPr"` + SpPr *xlsxSpPr `xml:"xdr:spPr"` + Style *xdrStyle `xml:"xdr:style"` + TxBody *xdrTxBody `xml:"xdr:txBody"` +} + +// xdrNvSpPr (Non-Visual Properties for a Shape) directly maps the xdr:nvSpPr +// element. This element specifies all non-visual properties for a shape. This +// element is a container for the non-visual identification properties, shape +// properties and application properties that are to be associated with a shape. +// This allows for additional information that does not affect the appearance of +// the shape to be stored. +type xdrNvSpPr struct { + CNvPr *xlsxCNvPr `xml:"xdr:cNvPr"` + CNvSpPr *xdrCNvSpPr `xml:"xdr:cNvSpPr"` +} + +// xdrCNvSpPr (Connection Non-Visual Shape Properties) directly maps the +// xdr:cNvSpPr element. This element specifies the set of non-visual properties +// for a connection shape. These properties specify all data about the +// connection shape which do not affect its display within a spreadsheet. +type xdrCNvSpPr struct { + TxBox bool `xml:"txBox,attr"` +} + +// xdrStyle (Shape Style) directly maps the xdr:style element. The element +// specifies the style that is applied to a shape and the corresponding +// references for each of the style components such as lines and fills. +type xdrStyle struct { + LnRef *aRef `xml:"a:lnRef"` + FillRef *aRef `xml:"a:fillRef"` + EffectRef *aRef `xml:"a:effectRef"` + FontRef *aFontRef `xml:"a:fontRef"` +} + +// aRef directly maps the a:lnRef, a:fillRef and a:effectRef element. +type aRef struct { + Idx int `xml:"idx,attr"` + ScrgbClr *aScrgbClr `xml:"a:scrgbClr"` + SchemeClr *attrValString `xml:"a:schemeClr"` + SrgbClr *attrValString `xml:"a:srgbClr"` +} + +// aScrgbClr (RGB Color Model - Percentage Variant) directly maps the a:scrgbClr +// element. This element specifies a color using the red, green, blue RGB color +// model. Each component, red, green, and blue is expressed as a percentage from +// 0% to 100%. A linear gamma of 1.0 is assumed. +type aScrgbClr struct { + R float64 `xml:"r,attr"` + G float64 `xml:"g,attr"` + B float64 `xml:"b,attr"` +} + +// aFontRef (Font Reference) directly maps the a:fontRef element. This element +// represents a reference to a themed font. When used it specifies which themed +// font to use along with a choice of color. +type aFontRef struct { + Idx string `xml:"idx,attr"` + SchemeClr *attrValString `xml:"a:schemeClr"` +} + +// xdrTxBody (Shape Text Body) directly maps the xdr:txBody element. This +// element specifies the existence of text to be contained within the +// corresponding shape. All visible text and visible text related properties are +// contained within this element. There can be multiple paragraphs and within +// paragraphs multiple runs of text. +type xdrTxBody struct { + BodyPr *aBodyPr `xml:"a:bodyPr"` + P []*aP `xml:"a:p"` +} + +// formatPicture directly maps the format settings of the picture. +type formatPicture struct { + FPrintsWithSheet bool `json:"print_obj"` + FLocksWithSheet bool `json:"locked"` + NoChangeAspect bool `json:"lock_aspect_ratio"` + OffsetX int `json:"x_offset"` + OffsetY int `json:"y_offset"` + XScale float64 `json:"x_scale"` + YScale float64 `json:"y_scale"` + Hyperlink string `json:"hyperlink"` + HyperlinkType string `json:"hyperlink_type"` + Positioning string `json:"positioning"` +} + +// formatShape directly maps the format settings of the shape. +type formatShape struct { + Type string `json:"type"` + Width int `json:"width"` + Height int `json:"height"` + Format formatPicture `json:"format"` + Color formatShapeColor `json:"color"` + Paragraph []formatShapeParagraph `json:"paragraph"` +} + +// formatShapeParagraph directly maps the format settings of the paragraph in +// the shape. +type formatShapeParagraph struct { + Font formatFont `json:"font"` + Text string `json:"text"` +} + +// formatShapeColor directly maps the color settings of the shape. +type formatShapeColor struct { + Line string `json:"line"` + Fill string `json:"fill"` + Effect string `json:"effect"` +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlSharedStrings.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlSharedStrings.go new file mode 100644 index 0000000000..3fcf3d5bb7 --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlSharedStrings.go @@ -0,0 +1,55 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. + +package excelize + +import "encoding/xml" + +// xlsxSST directly maps the sst element from the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main. String values may +// be stored directly inside spreadsheet cell elements; however, storing the +// same value inside multiple cell elements can result in very large worksheet +// Parts, possibly resulting in performance degradation. The Shared String Table +// is an indexed list of string values, shared across the workbook, which allows +// implementations to store values only once. +type xlsxSST struct { + XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main sst"` + Count int `xml:"count,attr"` + UniqueCount int `xml:"uniqueCount,attr"` + SI []xlsxSI `xml:"si"` +} + +// xlsxSI directly maps the si element from the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have +// not checked this for completeness - it does as much as I need. +type xlsxSI struct { + T string `xml:"t"` + R []xlsxR `xml:"r"` +} + +// xlsxR directly maps the r element from the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have +// not checked this for completeness - it does as much as I need. +type xlsxR struct { + RPr *xlsxRPr `xml:"rPr"` + T string `xml:"t"` +} + +// xlsxRPr (Run Properties) specifies a set of run properties which shall be +// applied to the contents of the parent run after all style formatting has been +// applied to the text. These properties are defined as direct formatting, since +// they are directly applied to the run and supersede any formatting from +// styles. +type xlsxRPr struct { + B string `xml:"b,omitempty"` + Sz *attrValFloat `xml:"sz"` + Color *xlsxColor `xml:"color"` + RFont *attrValString `xml:"rFont"` + Family *attrValInt `xml:"family"` +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlStyles.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlStyles.go new file mode 100644 index 0000000000..fc53f7756c --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlStyles.go @@ -0,0 +1,365 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. + +package excelize + +import "encoding/xml" + +// xlsxStyleSheet directly maps the stylesheet element in the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have +// not checked it for completeness - it does as much as I need. +type xlsxStyleSheet struct { + XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main styleSheet"` + NumFmts *xlsxNumFmts `xml:"numFmts,omitempty"` + Fonts *xlsxFonts `xml:"fonts,omitempty"` + Fills *xlsxFills `xml:"fills,omitempty"` + Borders *xlsxBorders `xml:"borders,omitempty"` + CellStyleXfs *xlsxCellStyleXfs `xml:"cellStyleXfs,omitempty"` + CellXfs *xlsxCellXfs `xml:"cellXfs,omitempty"` + CellStyles *xlsxCellStyles `xml:"cellStyles,omitempty"` + Dxfs *xlsxDxfs `xml:"dxfs,omitempty"` + TableStyles *xlsxTableStyles `xml:"tableStyles,omitempty"` + Colors *xlsxStyleColors `xml:"colors,omitempty"` + ExtLst *xlsxExtLst `xml:"extLst"` +} + +// xlsxAlignment formatting information pertaining to text alignment in cells. +// There are a variety of choices for how text is aligned both horizontally and +// vertically, as well as indentation settings, and so on. +type xlsxAlignment struct { + Horizontal string `xml:"horizontal,attr,omitempty"` + Indent int `xml:"indent,attr,omitempty"` + JustifyLastLine bool `xml:"justifyLastLine,attr,omitempty"` + ReadingOrder uint64 `xml:"readingOrder,attr,omitempty"` + RelativeIndent int `xml:"relativeIndent,attr,omitempty"` + ShrinkToFit bool `xml:"shrinkToFit,attr,omitempty"` + TextRotation int `xml:"textRotation,attr,omitempty"` + Vertical string `xml:"vertical,attr,omitempty"` + WrapText bool `xml:"wrapText,attr,omitempty"` +} + +// xlsxProtection (Protection Properties) contains protection properties +// associated with the cell. Each cell has protection properties that can be +// set. The cell protection properties do not take effect unless the sheet has +// been protected. +type xlsxProtection struct { + Hidden bool `xml:"hidden,attr"` + Locked bool `xml:"locked,attr"` +} + +// xlsxLine directly maps the line style element in the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have +// not checked it for completeness - it does as much as I need. +type xlsxLine struct { + Style string `xml:"style,attr,omitempty"` + Color *xlsxColor `xml:"color,omitempty"` +} + +// xlsxColor is a common mapping used for both the fgColor and bgColor elements. +// Foreground color of the cell fill pattern. Cell fill patterns operate with +// two colors: a background color and a foreground color. These combine together +// to make a patterned cell fill. Background color of the cell fill pattern. +// Cell fill patterns operate with two colors: a background color and a +// foreground color. These combine together to make a patterned cell fill. +type xlsxColor struct { + Auto bool `xml:"auto,attr,omitempty"` + RGB string `xml:"rgb,attr,omitempty"` + Indexed int `xml:"indexed,attr,omitempty"` + Theme *int `xml:"theme,attr"` + Tint float64 `xml:"tint,attr,omitempty"` +} + +// xlsxFonts directly maps the font element. This element contains all font +// definitions for this workbook. +type xlsxFonts struct { + Count int `xml:"count,attr"` + Font []*xlsxFont `xml:"font"` +} + +// font directly maps the font element. +type font struct { + Name *attrValString `xml:"name"` + Charset *attrValInt `xml:"charset"` + Family *attrValInt `xml:"family"` + B bool `xml:"b,omitempty"` + I bool `xml:"i,omitempty"` + Strike bool `xml:"strike,omitempty"` + Outline bool `xml:"outline,omitempty"` + Shadow bool `xml:"shadow,omitempty"` + Condense bool `xml:"condense,omitempty"` + Extend bool `xml:"extend,omitempty"` + Color *xlsxColor `xml:"color"` + Sz *attrValInt `xml:"sz"` + U *attrValString `xml:"u"` + Scheme *attrValString `xml:"scheme"` +} + +// xlsxFont directly maps the font element. This element defines the properties +// for one of the fonts used in this workbook. +type xlsxFont struct { + Font string `xml:",innerxml"` +} + +// xlsxFills directly maps the fills element. This element defines the cell +// fills portion of the Styles part, consisting of a sequence of fill records. A +// cell fill consists of a background color, foreground color, and pattern to be +// applied across the cell. +type xlsxFills struct { + Count int `xml:"count,attr"` + Fill []*xlsxFill `xml:"fill,omitempty"` +} + +// xlsxFill directly maps the fill element. This element specifies fill +// formatting. +type xlsxFill struct { + PatternFill *xlsxPatternFill `xml:"patternFill,omitempty"` + GradientFill *xlsxGradientFill `xml:"gradientFill,omitempty"` +} + +// xlsxPatternFill directly maps the patternFill element in the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have +// not checked it for completeness - it does as much as I need. This element is +// used to specify cell fill information for pattern and solid color cell fills. +// For solid cell fills (no pattern), fgColor is used. For cell fills with +// patterns specified, then the cell fill color is specified by the bgColor +// element. +type xlsxPatternFill struct { + PatternType string `xml:"patternType,attr,omitempty"` + FgColor xlsxColor `xml:"fgColor,omitempty"` + BgColor xlsxColor `xml:"bgColor,omitempty"` +} + +// xlsxGradientFill defines a gradient-style cell fill. Gradient cell fills can +// use one or two colors as the end points of color interpolation. +type xlsxGradientFill struct { + Bottom float64 `xml:"bottom,attr,omitempty"` + Degree float64 `xml:"degree,attr,omitempty"` + Left float64 `xml:"left,attr,omitempty"` + Right float64 `xml:"right,attr,omitempty"` + Top float64 `xml:"top,attr,omitempty"` + Type string `xml:"type,attr,omitempty"` + Stop []*xlsxGradientFillStop `xml:"stop,omitempty"` +} + +// xlsxGradientFillStop directly maps the stop element. +type xlsxGradientFillStop struct { + Position float64 `xml:"position,attr"` + Color xlsxColor `xml:"color,omitempty"` +} + +// xlsxBorders directly maps the borders element. This element contains borders +// formatting information, specifying all border definitions for all cells in +// the workbook. +type xlsxBorders struct { + Count int `xml:"count,attr"` + Border []*xlsxBorder `xml:"border,omitempty"` +} + +// xlsxBorder directly maps the border element. Expresses a single set of cell +// border formats (left, right, top, bottom, diagonal). Color is optional. When +// missing, 'automatic' is implied. +type xlsxBorder struct { + DiagonalDown bool `xml:"diagonalDown,attr,omitempty"` + DiagonalUp bool `xml:"diagonalUp,attr,omitempty"` + Outline bool `xml:"outline,attr,omitempty"` + Left xlsxLine `xml:"left,omitempty"` + Right xlsxLine `xml:"right,omitempty"` + Top xlsxLine `xml:"top,omitempty"` + Bottom xlsxLine `xml:"bottom,omitempty"` + Diagonal xlsxLine `xml:"diagonal,omitempty"` +} + +// xlsxCellStyles directly maps the cellStyles element. This element contains +// the named cell styles, consisting of a sequence of named style records. A +// named cell style is a collection of direct or themed formatting (e.g., cell +// border, cell fill, and font type/size/style) grouped together into a single +// named style, and can be applied to a cell. +type xlsxCellStyles struct { + XMLName xml.Name `xml:"cellStyles"` + Count int `xml:"count,attr"` + CellStyle []*xlsxCellStyle `xml:"cellStyle,omitempty"` +} + +// xlsxCellStyle directly maps the cellStyle element. This element represents +// the name and related formatting records for a named cell style in this +// workbook. +type xlsxCellStyle struct { + XMLName xml.Name `xml:"cellStyle"` + BuiltInID *int `xml:"builtinId,attr,omitempty"` + CustomBuiltIn *bool `xml:"customBuiltin,attr,omitempty"` + Hidden *bool `xml:"hidden,attr,omitempty"` + ILevel *bool `xml:"iLevel,attr,omitempty"` + Name string `xml:"name,attr"` + XfID int `xml:"xfId,attr"` +} + +// xlsxCellStyleXfs directly maps the cellStyleXfs element. This element +// contains the master formatting records (xf's) which define the formatting for +// all named cell styles in this workbook. Master formatting records reference +// individual elements of formatting (e.g., number format, font definitions, +// cell fills, etc) by specifying a zero-based index into those collections. +// Master formatting records also specify whether to apply or ignore particular +// aspects of formatting. +type xlsxCellStyleXfs struct { + Count int `xml:"count,attr"` + Xf []xlsxXf `xml:"xf,omitempty"` +} + +// xlsxXf directly maps the xf element. A single xf element describes all of the +// formatting for a cell. +type xlsxXf struct { + ApplyAlignment bool `xml:"applyAlignment,attr"` + ApplyBorder bool `xml:"applyBorder,attr"` + ApplyFill bool `xml:"applyFill,attr"` + ApplyFont bool `xml:"applyFont,attr"` + ApplyNumberFormat bool `xml:"applyNumberFormat,attr"` + ApplyProtection bool `xml:"applyProtection,attr"` + BorderID int `xml:"borderId,attr"` + FillID int `xml:"fillId,attr"` + FontID int `xml:"fontId,attr"` + NumFmtID int `xml:"numFmtId,attr"` + PivotButton bool `xml:"pivotButton,attr,omitempty"` + QuotePrefix bool `xml:"quotePrefix,attr,omitempty"` + XfID *int `xml:"xfId,attr"` + Alignment *xlsxAlignment `xml:"alignment"` + Protection *xlsxProtection `xml:"protection"` +} + +// xlsxCellXfs directly maps the cellXfs element. This element contains the +// master formatting records (xf) which define the formatting applied to cells +// in this workbook. These records are the starting point for determining the +// formatting for a cell. Cells in the Sheet Part reference the xf records by +// zero-based index. +type xlsxCellXfs struct { + Count int `xml:"count,attr"` + Xf []xlsxXf `xml:"xf,omitempty"` +} + +// xlsxDxfs directly maps the dxfs element. This element contains the master +// differential formatting records (dxf's) which define formatting for all non- +// cell formatting in this workbook. Whereas xf records fully specify a +// particular aspect of formatting (e.g., cell borders) by referencing those +// formatting definitions elsewhere in the Styles part, dxf records specify +// incremental (or differential) aspects of formatting directly inline within +// the dxf element. The dxf formatting is to be applied on top of or in addition +// to any formatting already present on the object using the dxf record. +type xlsxDxfs struct { + Count int `xml:"count,attr"` + Dxfs []*xlsxDxf `xml:"dxf,omitempty"` +} + +// xlsxDxf directly maps the dxf element. A single dxf record, expressing +// incremental formatting to be applied. +type xlsxDxf struct { + Dxf string `xml:",innerxml"` +} + +// dxf directly maps the dxf element. +type dxf struct { + Font *font `xml:"font"` + NumFmt *xlsxNumFmt `xml:"numFmt"` + Fill *xlsxFill `xml:"fill"` + Alignment *xlsxAlignment `xml:"alignment"` + Border *xlsxBorder `xml:"border"` + Protection *xlsxProtection `xml:"protection"` + ExtLst *xlsxExt `xml:"extLst"` +} + +// xlsxTableStyles directly maps the tableStyles element. This element +// represents a collection of Table style definitions for Table styles and +// PivotTable styles used in this workbook. It consists of a sequence of +// tableStyle records, each defining a single Table style. +type xlsxTableStyles struct { + Count int `xml:"count,attr"` + DefaultPivotStyle string `xml:"defaultPivotStyle,attr"` + DefaultTableStyle string `xml:"defaultTableStyle,attr"` + TableStyles []*xlsxTableStyle `xml:"tableStyle,omitempty"` +} + +// xlsxTableStyle directly maps the tableStyle element. This element represents +// a single table style definition that indicates how a spreadsheet application +// should format and display a table. +type xlsxTableStyle struct { + Name string `xml:"name,attr,omitempty"` + Pivot int `xml:"pivot,attr"` + Count int `xml:"count,attr,omitempty"` + Table bool `xml:"table,attr,omitempty"` + TableStyleElement string `xml:",innerxml"` +} + +// xlsxNumFmts directly maps the numFmts element. This element defines the +// number formats in this workbook, consisting of a sequence of numFmt records, +// where each numFmt record defines a particular number format, indicating how +// to format and render the numeric value of a cell. +type xlsxNumFmts struct { + Count int `xml:"count,attr"` + NumFmt []*xlsxNumFmt `xml:"numFmt,omitempty"` +} + +// xlsxNumFmt directly maps the numFmt element. This element specifies number +// format properties which indicate how to format and render the numeric value +// of a cell. +type xlsxNumFmt struct { + NumFmtID int `xml:"numFmtId,attr,omitempty"` + FormatCode string `xml:"formatCode,attr,omitempty"` +} + +// xlsxStyleColors directly maps the colors element. Color information +// associated with this stylesheet. This collection is written whenever the +// legacy color palette has been modified (backwards compatibility settings) or +// a custom color has been selected while using this workbook. +type xlsxStyleColors struct { + Color string `xml:",innerxml"` +} + +// formatFont directly maps the styles settings of the fonts. +type formatFont struct { + Bold bool `json:"bold"` + Italic bool `json:"italic"` + Underline string `json:"underline"` + Family string `json:"family"` + Size int `json:"size"` + Color string `json:"color"` +} + +// formatStyle directly maps the styles settings of the cells. +type formatStyle struct { + Border []struct { + Type string `json:"type"` + Color string `json:"color"` + Style int `json:"style"` + } `json:"border"` + Fill struct { + Type string `json:"type"` + Pattern int `json:"pattern"` + Color []string `json:"color"` + Shading int `json:"shading"` + } `json:"fill"` + Font *formatFont `json:"font"` + Alignment *struct { + Horizontal string `json:"horizontal"` + Indent int `json:"indent"` + JustifyLastLine bool `json:"justify_last_line"` + ReadingOrder uint64 `json:"reading_order"` + RelativeIndent int `json:"relative_indent"` + ShrinkToFit bool `json:"shrink_to_fit"` + TextRotation int `json:"text_rotation"` + Vertical string `json:"vertical"` + WrapText bool `json:"wrap_text"` + } `json:"alignment"` + Protection *struct { + Hidden bool `json:"hidden"` + Locked bool `json:"locked"` + } `json:"protection"` + NumFmt int `json:"number_format"` + DecimalPlaces int `json:"decimal_places"` + CustomNumFmt *string `json:"custom_number_format"` + Lang string `json:"lang"` + NegRed bool `json:"negred"` +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlTable.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlTable.go new file mode 100644 index 0000000000..6d27dc9d44 --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlTable.go @@ -0,0 +1,214 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. + +package excelize + +import "encoding/xml" + +// xlsxTable directly maps the table element. A table helps organize and provide +// structure to lists of information in a worksheet. Tables have clearly labeled +// columns, rows, and data regions. Tables make it easier for users to sort, +// analyze, format, manage, add, and delete information. This element is the +// root element for a table that is not a single cell XML table. +type xlsxTable struct { + XMLName xml.Name `xml:"table"` + XMLNS string `xml:"xmlns,attr"` + DataCellStyle string `xml:"dataCellStyle,attr,omitempty"` + DataDxfID int `xml:"dataDxfId,attr,omitempty"` + DisplayName string `xml:"displayName,attr,omitempty"` + HeaderRowBorderDxfID int `xml:"headerRowBorderDxfId,attr,omitempty"` + HeaderRowCellStyle string `xml:"headerRowCellStyle,attr,omitempty"` + HeaderRowCount int `xml:"headerRowCount,attr,omitempty"` + HeaderRowDxfID int `xml:"headerRowDxfId,attr,omitempty"` + ID int `xml:"id,attr"` + InsertRow bool `xml:"insertRow,attr,omitempty"` + InsertRowShift bool `xml:"insertRowShift,attr,omitempty"` + Name string `xml:"name,attr"` + Published bool `xml:"published,attr,omitempty"` + Ref string `xml:"ref,attr"` + TotalsRowCount int `xml:"totalsRowCount,attr,omitempty"` + TotalsRowDxfID int `xml:"totalsRowDxfId,attr,omitempty"` + TotalsRowShown bool `xml:"totalsRowShown,attr"` + AutoFilter *xlsxAutoFilter `xml:"autoFilter"` + TableColumns *xlsxTableColumns `xml:"tableColumns"` + TableStyleInfo *xlsxTableStyleInfo `xml:"tableStyleInfo"` +} + +// xlsxAutoFilter temporarily hides rows based on a filter criteria, which is +// applied column by column to a table of data in the worksheet. This collection +// expresses AutoFilter settings. +type xlsxAutoFilter struct { + Ref string `xml:"ref,attr"` + FilterColumn *xlsxFilterColumn `xml:"filterColumn"` +} + +// xlsxFilterColumn directly maps the filterColumn element. The filterColumn +// collection identifies a particular column in the AutoFilter range and +// specifies filter information that has been applied to this column. If a +// column in the AutoFilter range has no criteria specified, then there is no +// corresponding filterColumn collection expressed for that column. +type xlsxFilterColumn struct { + ColID int `xml:"colId,attr"` + HiddenButton bool `xml:"hiddenButton,attr,omitempty"` + ShowButton bool `xml:"showButton,attr,omitempty"` + CustomFilters *xlsxCustomFilters `xml:"customFilters"` + Filters *xlsxFilters `xml:"filters"` + ColorFilter *xlsxColorFilter `xml:"colorFilter"` + DynamicFilter *xlsxDynamicFilter `xml:"dynamicFilter"` + IconFilter *xlsxIconFilter `xml:"iconFilter"` + Top10 *xlsxTop10 `xml:"top10"` +} + +// xlsxCustomFilters directly maps the customFilters element. When there is more +// than one custom filter criteria to apply (an 'and' or 'or' joining two +// criteria), then this element groups the customFilter elements together. +type xlsxCustomFilters struct { + And bool `xml:"and,attr,omitempty"` + CustomFilter []*xlsxCustomFilter `xml:"customFilter"` +} + +// xlsxCustomFilter directly maps the customFilter element. A custom AutoFilter +// specifies an operator and a value. There can be at most two customFilters +// specified, and in that case the parent element specifies whether the two +// conditions are joined by 'and' or 'or'. For any cells whose values do not +// meet the specified criteria, the corresponding rows shall be hidden from view +// when the filter is applied. +type xlsxCustomFilter struct { + Operator string `xml:"operator,attr,omitempty"` + Val string `xml:"val,attr,omitempty"` +} + +// xlsxFilters directly maps the filters (Filter Criteria) element. When +// multiple values are chosen to filter by, or when a group of date values are +// chosen to filter by, this element groups those criteria together. +type xlsxFilters struct { + Blank bool `xml:"blank,attr,omitempty"` + CalendarType string `xml:"calendarType,attr,omitempty"` + Filter []*xlsxFilter `xml:"filter"` + DateGroupItem []*xlsxDateGroupItem `xml:"dateGroupItem"` +} + +// xlsxFilter directly maps the filter element. This element expresses a filter +// criteria value. +type xlsxFilter struct { + Val string `xml:"val,attr,omitempty"` +} + +// xlsxColorFilter directly maps the colorFilter element. This element specifies +// the color to filter by and whether to use the cell's fill or font color in +// the filter criteria. If the cell's font or fill color does not match the +// color specified in the criteria, the rows corresponding to those cells are +// hidden from view. +type xlsxColorFilter struct { + CellColor bool `xml:"cellColor,attr"` + DxfID int `xml:"dxfId,attr"` +} + +// xlsxDynamicFilter directly maps the dynamicFilter element. This collection +// specifies dynamic filter criteria. These criteria are considered dynamic +// because they can change, either with the data itself (e.g., "above average") +// or with the current system date (e.g., show values for "today"). For any +// cells whose values do not meet the specified criteria, the corresponding rows +// shall be hidden from view when the filter is applied. +type xlsxDynamicFilter struct { + MaxValISO string `xml:"maxValIso,attr,omitempty"` + Type string `xml:"type,attr,omitempty"` + Val float64 `xml:"val,attr,omitempty"` + ValISO string `xml:"valIso,attr,omitempty"` +} + +// xlsxIconFilter directly maps the iconFilter element. This element specifies +// the icon set and particular icon within that set to filter by. For any cells +// whose icon does not match the specified criteria, the corresponding rows +// shall be hidden from view when the filter is applied. +type xlsxIconFilter struct { + IconID int `xml:"iconId,attr"` + IconSet string `xml:"iconSet,attr,omitempty"` +} + +// xlsxTop10 directly maps the top10 element. This element specifies the top N +// (percent or number of items) to filter by. +type xlsxTop10 struct { + FilterVal float64 `xml:"filterVal,attr,omitempty"` + Percent bool `xml:"percent,attr,omitempty"` + Top bool `xml:"top,attr"` + Val float64 `xml:"val,attr,omitempty"` +} + +// xlsxDateGroupItem directly maps the dateGroupItem element. This collection is +// used to express a group of dates or times which are used in an AutoFilter +// criteria. [Note: See parent element for an example. end note] Values are +// always written in the calendar type of the first date encountered in the +// filter range, so that all subsequent dates, even when formatted or +// represented by other calendar types, can be correctly compared for the +// purposes of filtering. +type xlsxDateGroupItem struct { + DateTimeGrouping string `xml:"dateTimeGrouping,attr,omitempty"` + Day int `xml:"day,attr,omitempty"` + Hour int `xml:"hour,attr,omitempty"` + Minute int `xml:"minute,attr,omitempty"` + Month int `xml:"month,attr,omitempty"` + Second int `xml:"second,attr,omitempty"` + Year int `xml:"year,attr,omitempty"` +} + +// xlsxTableColumns directly maps the element representing the collection of all +// table columns for this table. +type xlsxTableColumns struct { + Count int `xml:"count,attr"` + TableColumn []*xlsxTableColumn `xml:"tableColumn"` +} + +// xlsxTableColumn directly maps the element representing a single column for +// this table. +type xlsxTableColumn struct { + DataCellStyle string `xml:"dataCellStyle,attr,omitempty"` + DataDxfID int `xml:"dataDxfId,attr,omitempty"` + HeaderRowCellStyle string `xml:"headerRowCellStyle,attr,omitempty"` + HeaderRowDxfID int `xml:"headerRowDxfId,attr,omitempty"` + ID int `xml:"id,attr"` + Name string `xml:"name,attr"` + QueryTableFieldID int `xml:"queryTableFieldId,attr,omitempty"` + TotalsRowCellStyle string `xml:"totalsRowCellStyle,attr,omitempty"` + TotalsRowDxfID int `xml:"totalsRowDxfId,attr,omitempty"` + TotalsRowFunction string `xml:"totalsRowFunction,attr,omitempty"` + TotalsRowLabel string `xml:"totalsRowLabel,attr,omitempty"` + UniqueName string `xml:"uniqueName,attr,omitempty"` +} + +// xlsxTableStyleInfo directly maps the tableStyleInfo element. This element +// describes which style is used to display this table, and specifies which +// portions of the table have the style applied. +type xlsxTableStyleInfo struct { + Name string `xml:"name,attr,omitempty"` + ShowFirstColumn bool `xml:"showFirstColumn,attr"` + ShowLastColumn bool `xml:"showLastColumn,attr"` + ShowRowStripes bool `xml:"showRowStripes,attr"` + ShowColumnStripes bool `xml:"showColumnStripes,attr"` +} + +// formatTable directly maps the format settings of the table. +type formatTable struct { + TableName string `json:"table_name"` + TableStyle string `json:"table_style"` + ShowFirstColumn bool `json:"show_first_column"` + ShowLastColumn bool `json:"show_last_column"` + ShowRowStripes bool `json:"show_row_stripes"` + ShowColumnStripes bool `json:"show_column_stripes"` +} + +// formatAutoFilter directly maps the auto filter settings. +type formatAutoFilter struct { + Column string `json:"column"` + Expression string `json:"expression"` + FilterList []struct { + Column string `json:"column"` + Value []int `json:"value"` + } `json:"filter_list"` +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlTheme.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlTheme.go new file mode 100644 index 0000000000..01d0054c27 --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlTheme.go @@ -0,0 +1,149 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. + +package excelize + +import "encoding/xml" + +// xlsxTheme directly maps the theme element in the namespace +// http://schemas.openxmlformats.org/drawingml/2006/main +type xlsxTheme struct { + ThemeElements xlsxThemeElements `xml:"themeElements"` + ObjectDefaults xlsxObjectDefaults `xml:"objectDefaults"` + ExtraClrSchemeLst xlsxExtraClrSchemeLst `xml:"extraClrSchemeLst"` + ExtLst *xlsxExtLst `xml:"extLst"` +} + +// objectDefaults element allows for the definition of default shape, line, +// and textbox formatting properties. An application can use this information +// to format a shape (or text) initially on insertion into a document. +type xlsxObjectDefaults struct { + ObjectDefaults string `xml:",innerxml"` +} + +// xlsxExtraClrSchemeLst element is a container for the list of extra color +// schemes present in a document. +type xlsxExtraClrSchemeLst struct { + ExtraClrSchemeLst string `xml:",innerxml"` +} + +// xlsxThemeElements directly maps the element defines the theme formatting +// options for the theme and is the workhorse of the theme. This is where the +// bulk of the shared theme information is contained and used by a document. +// This element contains the color scheme, font scheme, and format scheme +// elements which define the different formatting aspects of what a theme +// defines. +type xlsxThemeElements struct { + ClrScheme xlsxClrScheme `xml:"clrScheme"` + FontScheme xlsxFontScheme `xml:"fontScheme"` + FmtScheme xlsxFmtScheme `xml:"fmtScheme"` +} + +// xlsxClrScheme element specifies the theme color, stored in the document's +// Theme part to which the value of this theme color shall be mapped. This +// mapping enables multiple theme colors to be chained together. +type xlsxClrScheme struct { + Name string `xml:"name,attr"` + Children []xlsxClrSchemeEl `xml:",any"` +} + +// xlsxFontScheme element defines the font scheme within the theme. The font +// scheme consists of a pair of major and minor fonts for which to use in a +// document. The major font corresponds well with the heading areas of a +// document, and the minor font corresponds well with the normal text or +// paragraph areas. +type xlsxFontScheme struct { + Name string `xml:"name,attr"` + MajorFont xlsxMajorFont `xml:"majorFont"` + MinorFont xlsxMinorFont `xml:"minorFont"` + ExtLst *xlsxExtLst `xml:"extLst"` +} + +// xlsxMajorFont element defines the set of major fonts which are to be used +// under different languages or locals. +type xlsxMajorFont struct { + Children []xlsxFontSchemeEl `xml:",any"` +} + +// xlsxMinorFont element defines the set of minor fonts that are to be used +// under different languages or locals. +type xlsxMinorFont struct { + Children []xlsxFontSchemeEl `xml:",any"` +} + +// xlsxFmtScheme element contains the background fill styles, effect styles, +// fill styles, and line styles which define the style matrix for a theme. The +// style matrix consists of subtle, moderate, and intense fills, lines, and +// effects. The background fills are not generally thought of to directly be +// associated with the matrix, but do play a role in the style of the overall +// document. Usually, a given object chooses a single line style, a single +// fill style, and a single effect style in order to define the overall final +// look of the object. +type xlsxFmtScheme struct { + Name string `xml:"name,attr"` + FillStyleLst xlsxFillStyleLst `xml:"fillStyleLst"` + LnStyleLst xlsxLnStyleLst `xml:"lnStyleLst"` + EffectStyleLst xlsxEffectStyleLst `xml:"effectStyleLst"` + BgFillStyleLst xlsxBgFillStyleLst `xml:"bgFillStyleLst"` +} + +// xlsxFillStyleLst element defines a set of three fill styles that are used +// within a theme. The three fill styles are arranged in order from subtle to +// moderate to intense. +type xlsxFillStyleLst struct { + FillStyleLst string `xml:",innerxml"` +} + +// xlsxLnStyleLst element defines a list of three line styles for use within a +// theme. The three line styles are arranged in order from subtle to moderate +// to intense versions of lines. This list makes up part of the style matrix. +type xlsxLnStyleLst struct { + LnStyleLst string `xml:",innerxml"` +} + +// xlsxEffectStyleLst element defines a set of three effect styles that create +// the effect style list for a theme. The effect styles are arranged in order +// of subtle to moderate to intense. +type xlsxEffectStyleLst struct { + EffectStyleLst string `xml:",innerxml"` +} + +// xlsxBgFillStyleLst element defines a list of background fills that are +// used within a theme. The background fills consist of three fills, arranged +// in order from subtle to moderate to intense. +type xlsxBgFillStyleLst struct { + BgFillStyleLst string `xml:",innerxml"` +} + +// xlsxClrScheme maps to children of the clrScheme element in the namespace +// http://schemas.openxmlformats.org/drawingml/2006/main - currently I have +// not checked it for completeness - it does as much as I need. +type xlsxClrSchemeEl struct { + XMLName xml.Name + SysClr *xlsxSysClr `xml:"sysClr"` + SrgbClr *attrValString `xml:"srgbClr"` +} + +// xlsxFontSchemeEl directly maps the major and minor font of the style's font +// scheme. +type xlsxFontSchemeEl struct { + XMLName xml.Name + Script string `xml:"script,attr,omitempty"` + Typeface string `xml:"typeface,attr"` + Panose string `xml:"panose,attr,omitempty"` + PitchFamily string `xml:"pitchFamily,attr,omitempty"` + Charset string `xml:"charset,attr,omitempty"` +} + +// xlsxSysClr element specifies a color bound to predefined operating system +// elements. +type xlsxSysClr struct { + Val string `xml:"val,attr"` + LastClr string `xml:"lastClr,attr"` +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlWorkbook.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlWorkbook.go new file mode 100644 index 0000000000..ad66f4295c --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlWorkbook.go @@ -0,0 +1,291 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. + +package excelize + +import "encoding/xml" + +// xmlxWorkbookRels contains xmlxWorkbookRelations which maps sheet id and sheet XML. +type xlsxWorkbookRels struct { + XMLName xml.Name `xml:"http://schemas.openxmlformats.org/package/2006/relationships Relationships"` + Relationships []xlsxWorkbookRelation `xml:"Relationship"` +} + +// xmlxWorkbookRelation maps sheet id and xl/worksheets/_rels/sheet%d.xml.rels +type xlsxWorkbookRelation struct { + ID string `xml:"Id,attr"` + Target string `xml:",attr"` + Type string `xml:",attr"` + TargetMode string `xml:",attr,omitempty"` +} + +// xlsxWorkbook directly maps the workbook element from the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have +// not checked it for completeness - it does as much as I need. +type xlsxWorkbook struct { + XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main workbook"` + FileVersion *xlsxFileVersion `xml:"fileVersion"` + WorkbookPr *xlsxWorkbookPr `xml:"workbookPr"` + WorkbookProtection *xlsxWorkbookProtection `xml:"workbookProtection"` + BookViews xlsxBookViews `xml:"bookViews"` + Sheets xlsxSheets `xml:"sheets"` + ExternalReferences *xlsxExternalReferences `xml:"externalReferences"` + DefinedNames *xlsxDefinedNames `xml:"definedNames"` + CalcPr *xlsxCalcPr `xml:"calcPr"` + CustomWorkbookViews *xlsxCustomWorkbookViews `xml:"customWorkbookViews"` + PivotCaches *xlsxPivotCaches `xml:"pivotCaches"` + ExtLst *xlsxExtLst `xml:"extLst"` + FileRecoveryPr *xlsxFileRecoveryPr `xml:"fileRecoveryPr"` +} + +// xlsxFileRecoveryPr maps sheet recovery information. This element defines +// properties that track the state of the workbook file, such as whether the +// file was saved during a crash, or whether it should be opened in auto-recover +// mode. +type xlsxFileRecoveryPr struct { + AutoRecover bool `xml:"autoRecover,attr,omitempty"` + CrashSave bool `xml:"crashSave,attr,omitempty"` + DataExtractLoad bool `xml:"dataExtractLoad,attr,omitempty"` + RepairLoad bool `xml:"repairLoad,attr,omitempty"` +} + +// xlsxWorkbookProtection directly maps the workbookProtection element. This +// element specifies options for protecting data in the workbook. Applications +// might use workbook protection to prevent anyone from accidentally changing, +// moving, or deleting important data. This protection can be ignored by +// applications which choose not to support this optional protection mechanism. +// When a password is to be hashed and stored in this element, it shall be +// hashed as defined below, starting from a UTF-16LE encoded string value. If +// there is a leading BOM character (U+FEFF) in the encoded password it is +// removed before hash calculation. +type xlsxWorkbookProtection struct { + LockRevision bool `xml:"lockRevision,attr,omitempty"` + LockStructure bool `xml:"lockStructure,attr,omitempty"` + LockWindows bool `xml:"lockWindows,attr,omitempty"` + RevisionsAlgorithmName string `xml:"revisionsAlgorithmName,attr,omitempty"` + RevisionsHashValue string `xml:"revisionsHashValue,attr,omitempty"` + RevisionsSaltValue string `xml:"revisionsSaltValue,attr,omitempty"` + RevisionsSpinCount int `xml:"revisionsSpinCount,attr,omitempty"` + WorkbookAlgorithmName string `xml:"workbookAlgorithmName,attr,omitempty"` + WorkbookHashValue string `xml:"workbookHashValue,attr,omitempty"` + WorkbookSaltValue string `xml:"workbookSaltValue,attr,omitempty"` + WorkbookSpinCount int `xml:"workbookSpinCount,attr,omitempty"` +} + +// xlsxFileVersion directly maps the fileVersion element. This element defines +// properties that track which version of the application accessed the data and +// source code contained in the file. +type xlsxFileVersion struct { + AppName string `xml:"appName,attr,omitempty"` + CodeName string `xml:"codeName,attr,omitempty"` + LastEdited string `xml:"lastEdited,attr,omitempty"` + LowestEdited string `xml:"lowestEdited,attr,omitempty"` + RupBuild string `xml:"rupBuild,attr,omitempty"` +} + +// xlsxWorkbookPr directly maps the workbookPr element from the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main This element +// defines a collection of workbook properties. +type xlsxWorkbookPr struct { + AllowRefreshQuery bool `xml:"allowRefreshQuery,attr,omitempty"` + AutoCompressPictures bool `xml:"autoCompressPictures,attr,omitempty"` + BackupFile bool `xml:"backupFile,attr,omitempty"` + CheckCompatibility bool `xml:"checkCompatibility,attr,omitempty"` + CodeName string `xml:"codeName,attr,omitempty"` + Date1904 bool `xml:"date1904,attr,omitempty"` + DefaultThemeVersion string `xml:"defaultThemeVersion,attr,omitempty"` + FilterPrivacy bool `xml:"filterPrivacy,attr,omitempty"` + HidePivotFieldList bool `xml:"hidePivotFieldList,attr,omitempty"` + PromptedSolutions bool `xml:"promptedSolutions,attr,omitempty"` + PublishItems bool `xml:"publishItems,attr,omitempty"` + RefreshAllConnections bool `xml:"refreshAllConnections,attr,omitempty"` + SaveExternalLinkValues bool `xml:"saveExternalLinkValues,attr,omitempty"` + ShowBorderUnselectedTables bool `xml:"showBorderUnselectedTables,attr,omitempty"` + ShowInkAnnotation bool `xml:"showInkAnnotation,attr,omitempty"` + ShowObjects string `xml:"showObjects,attr,omitempty"` + ShowPivotChartFilter bool `xml:"showPivotChartFilter,attr,omitempty"` + UpdateLinks string `xml:"updateLinks,attr,omitempty"` +} + +// xlsxBookViews directly maps the bookViews element. This element specifies the +// collection of workbook views of the enclosing workbook. Each view can specify +// a window position, filter options, and other configurations. There is no +// limit on the number of workbook views that can be defined for a workbook. +type xlsxBookViews struct { + WorkBookView []xlsxWorkBookView `xml:"workbookView"` +} + +// xlsxWorkBookView directly maps the workbookView element from the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main This element +// specifies a single Workbook view. +type xlsxWorkBookView struct { + ActiveTab int `xml:"activeTab,attr,omitempty"` + AutoFilterDateGrouping bool `xml:"autoFilterDateGrouping,attr,omitempty"` + FirstSheet int `xml:"firstSheet,attr,omitempty"` + Minimized bool `xml:"minimized,attr,omitempty"` + ShowHorizontalScroll bool `xml:"showHorizontalScroll,attr,omitempty"` + ShowSheetTabs bool `xml:"showSheetTabs,attr,omitempty"` + ShowVerticalScroll bool `xml:"showVerticalScroll,attr,omitempty"` + TabRatio int `xml:"tabRatio,attr,omitempty"` + Visibility string `xml:"visibility,attr,omitempty"` + WindowHeight int `xml:"windowHeight,attr,omitempty"` + WindowWidth int `xml:"windowWidth,attr,omitempty"` + XWindow string `xml:"xWindow,attr,omitempty"` + YWindow string `xml:"yWindow,attr,omitempty"` +} + +// xlsxSheets directly maps the sheets element from the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main. +type xlsxSheets struct { + Sheet []xlsxSheet `xml:"sheet"` +} + +// xlsxSheet directly maps the sheet element from the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have +// not checked it for completeness - it does as much as I need. +type xlsxSheet struct { + Name string `xml:"name,attr,omitempty"` + SheetID int `xml:"sheetId,attr,omitempty"` + ID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"` + State string `xml:"state,attr,omitempty"` +} + +// xlsxExternalReferences directly maps the externalReferences element of the +// external workbook references part. +type xlsxExternalReferences struct { + ExternalReference []xlsxExternalReference `xml:"externalReference"` +} + +// xlsxExternalReference directly maps the externalReference element of the +// external workbook references part. +type xlsxExternalReference struct { + RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"` +} + +// xlsxPivotCaches element enumerates pivot cache definition parts used by pivot +// tables and formulas in this workbook. +type xlsxPivotCaches struct { + PivotCache []xlsxPivotCache `xml:"pivotCache"` +} + +// xlsxPivotCache directly maps the pivotCache element. +type xlsxPivotCache struct { + CacheID int `xml:"cacheId,attr,omitempty"` + RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"` +} + +// extLst element provides a convention for extending spreadsheetML in +// predefined locations. The locations shall be denoted with the extLst element, +// and are called extension lists. Extension list locations within the markup +// document are specified in the markup specification and can be used to store +// extensions to the markup specification, whether those are future version +// extensions of the markup specification or are private extensions implemented +// independently from the markup specification. Markup within an extension might +// not be understood by a consumer. +type xlsxExtLst struct { + Ext string `xml:",innerxml"` +} + +// xlsxDefinedNames directly maps the definedNames element. This element defines +// the collection of defined names for this workbook. Defined names are +// descriptive names to represent cells, ranges of cells, formulas, or constant +// values. Defined names can be used to represent a range on any worksheet. +type xlsxDefinedNames struct { + DefinedName []xlsxDefinedName `xml:"definedName"` +} + +// xlsxDefinedName directly maps the definedName element from the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main This element +// defines a defined name within this workbook. A defined name is descriptive +// text that is used to represents a cell, range of cells, formula, or constant +// value. For a descriptions of the attributes see https://msdn.microsoft.com/en-us/library/office/documentformat.openxml.spreadsheet.definedname.aspx +type xlsxDefinedName struct { + Comment string `xml:"comment,attr,omitempty"` + CustomMenu string `xml:"customMenu,attr,omitempty"` + Description string `xml:"description,attr,omitempty"` + Function bool `xml:"function,attr,omitempty"` + FunctionGroupID int `xml:"functionGroupId,attr,omitempty"` + Help string `xml:"help,attr,omitempty"` + Hidden bool `xml:"hidden,attr,omitempty"` + LocalSheetID *int `xml:"localSheetId,attr"` + Name string `xml:"name,attr,omitempty"` + PublishToServer bool `xml:"publishToServer,attr,omitempty"` + ShortcutKey string `xml:"shortcutKey,attr,omitempty"` + StatusBar string `xml:"statusBar,attr,omitempty"` + VbProcedure bool `xml:"vbProcedure,attr,omitempty"` + WorkbookParameter bool `xml:"workbookParameter,attr,omitempty"` + Xlm bool `xml:"xml,attr,omitempty"` + Data string `xml:",chardata"` +} + +// xlsxCalcPr directly maps the calcPr element. This element defines the +// collection of properties the application uses to record calculation status +// and details. Calculation is the process of computing formulas and then +// displaying the results as values in the cells that contain the formulas. +type xlsxCalcPr struct { + CalcCompleted bool `xml:"calcCompleted,attr,omitempty"` + CalcID string `xml:"calcId,attr,omitempty"` + CalcMode string `xml:"calcMode,attr,omitempty"` + CalcOnSave bool `xml:"calcOnSave,attr,omitempty"` + ConcurrentCalc *bool `xml:"concurrentCalc,attr"` + ConcurrentManualCount int `xml:"concurrentManualCount,attr,omitempty"` + ForceFullCalc bool `xml:"forceFullCalc,attr,omitempty"` + FullCalcOnLoad bool `xml:"fullCalcOnLoad,attr,omitempty"` + FullPrecision bool `xml:"fullPrecision,attr,omitempty"` + Iterate bool `xml:"iterate,attr,omitempty"` + IterateCount int `xml:"iterateCount,attr,omitempty"` + IterateDelta float64 `xml:"iterateDelta,attr,omitempty"` + RefMode string `xml:"refMode,attr,omitempty"` +} + +// xlsxCustomWorkbookViews defines the collection of custom workbook views that +// are defined for this workbook. A customWorkbookView is similar in concept to +// a workbookView in that its attributes contain settings related to the way +// that the workbook should be displayed on a screen by a spreadsheet +// application. +type xlsxCustomWorkbookViews struct { + CustomWorkbookView []xlsxCustomWorkbookView `xml:"customWorkbookView"` +} + +// xlsxCustomWorkbookView directly maps the customWorkbookView element. This +// element specifies a single custom workbook view. A custom workbook view +// consists of a set of display and print settings that you can name and apply +// to a workbook. You can create more than one custom workbook view of the same +// workbook. Custom Workbook Views are not required in order to construct a +// valid SpreadsheetML document, and are not necessary if the document is never +// displayed by a spreadsheet application, or if the spreadsheet application has +// a fixed display for workbooks. However, if a spreadsheet application chooses +// to implement configurable display modes, the customWorkbookView element +// should be used to persist the settings for those display modes. +type xlsxCustomWorkbookView struct { + ActiveSheetID *int `xml:"activeSheetId,attr"` + AutoUpdate *bool `xml:"autoUpdate,attr"` + ChangesSavedWin *bool `xml:"changesSavedWin,attr"` + GUID *string `xml:"guid,attr"` + IncludeHiddenRowCol *bool `xml:"includeHiddenRowCol,attr"` + IncludePrintSettings *bool `xml:"includePrintSettings,attr"` + Maximized *bool `xml:"maximized,attr"` + MergeInterval int `xml:"mergeInterval,attr"` + Minimized *bool `xml:"minimized,attr"` + Name *string `xml:"name,attr"` + OnlySync *bool `xml:"onlySync,attr"` + PersonalView *bool `xml:"personalView,attr"` + ShowComments *string `xml:"showComments,attr"` + ShowFormulaBar *bool `xml:"showFormulaBar,attr"` + ShowHorizontalScroll *bool `xml:"showHorizontalScroll,attr"` + ShowObjects *string `xml:"showObjects,attr"` + ShowSheetTabs *bool `xml:"showSheetTabs,attr"` + ShowStatusbar *bool `xml:"showStatusbar,attr"` + ShowVerticalScroll *bool `xml:"showVerticalScroll,attr"` + TabRatio *int `xml:"tabRatio,attr"` + WindowHeight *int `xml:"windowHeight,attr"` + WindowWidth *int `xml:"windowWidth,attr"` + XWindow *int `xml:"xWindow,attr"` + YWindow *int `xml:"yWindow,attr"` +} diff --git a/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlWorksheet.go b/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlWorksheet.go new file mode 100644 index 0000000000..b3e887705d --- /dev/null +++ b/vendor/github.com/360EntSecGroup-Skylar/excelize/xmlWorksheet.go @@ -0,0 +1,629 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. + +package excelize + +import "encoding/xml" + +// xlsxWorksheet directly maps the worksheet element in the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have +// not checked it for completeness - it does as much as I need. +type xlsxWorksheet struct { + XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main worksheet"` + SheetPr *xlsxSheetPr `xml:"sheetPr"` + Dimension xlsxDimension `xml:"dimension"` + SheetViews xlsxSheetViews `xml:"sheetViews,omitempty"` + SheetFormatPr *xlsxSheetFormatPr `xml:"sheetFormatPr"` + Cols *xlsxCols `xml:"cols,omitempty"` + SheetData xlsxSheetData `xml:"sheetData"` + SheetProtection *xlsxSheetProtection `xml:"sheetProtection"` + AutoFilter *xlsxAutoFilter `xml:"autoFilter"` + MergeCells *xlsxMergeCells `xml:"mergeCells"` + PhoneticPr *xlsxPhoneticPr `xml:"phoneticPr"` + ConditionalFormatting []*xlsxConditionalFormatting `xml:"conditionalFormatting"` + DataValidations *xlsxDataValidations `xml:"dataValidations,omitempty"` + Hyperlinks *xlsxHyperlinks `xml:"hyperlinks"` + PrintOptions *xlsxPrintOptions `xml:"printOptions"` + PageMargins *xlsxPageMargins `xml:"pageMargins"` + PageSetUp *xlsxPageSetUp `xml:"pageSetup"` + HeaderFooter *xlsxHeaderFooter `xml:"headerFooter"` + Drawing *xlsxDrawing `xml:"drawing"` + LegacyDrawing *xlsxLegacyDrawing `xml:"legacyDrawing"` + Picture *xlsxPicture `xml:"picture"` + TableParts *xlsxTableParts `xml:"tableParts"` + ExtLst *xlsxExtLst `xml:"extLst"` +} + +// xlsxDrawing change r:id to rid in the namespace. +type xlsxDrawing struct { + RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"` +} + +// xlsxHeaderFooter directly maps the headerFooter element in the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main - When printed or +// viewed in page layout view (§18.18.69), each page of a worksheet can have a +// page header, a page footer, or both. The headers and footers on odd-numbered +// pages can differ from those on even-numbered pages, and the headers and +// footers on the first page can differ from those on odd- and even-numbered +// pages. In the latter case, the first page is not considered an odd page. +type xlsxHeaderFooter struct { + DifferentFirst bool `xml:"differentFirst,attr,omitempty"` + DifferentOddEven bool `xml:"differentOddEven,attr,omitempty"` + OddHeader []*xlsxOddHeader `xml:"oddHeader"` + OddFooter []*xlsxOddFooter `xml:"oddFooter"` +} + +// xlsxOddHeader directly maps the oddHeader element in the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have +// not checked it for completeness - it does as much as I need. +type xlsxOddHeader struct { + Content string `xml:",chardata"` +} + +// xlsxOddFooter directly maps the oddFooter element in the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have +// not checked it for completeness - it does as much as I need. +type xlsxOddFooter struct { + Content string `xml:",chardata"` +} + +// xlsxPageSetUp directly maps the pageSetup element in the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main - Page setup +// settings for the worksheet. +type xlsxPageSetUp struct { + BlackAndWhite bool `xml:"blackAndWhite,attr,omitempty"` + CellComments string `xml:"cellComments,attr,omitempty"` + Copies int `xml:"copies,attr,omitempty"` + Draft bool `xml:"draft,attr,omitempty"` + Errors string `xml:"errors,attr,omitempty"` + FirstPageNumber int `xml:"firstPageNumber,attr,omitempty"` + FitToHeight *int `xml:"fitToHeight,attr"` + FitToWidth int `xml:"fitToWidth,attr,omitempty"` + HorizontalDPI float32 `xml:"horizontalDpi,attr,omitempty"` + RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"` + Orientation string `xml:"orientation,attr,omitempty"` + PageOrder string `xml:"pageOrder,attr,omitempty"` + PaperHeight string `xml:"paperHeight,attr,omitempty"` + PaperSize string `xml:"paperSize,attr,omitempty"` + PaperWidth string `xml:"paperWidth,attr,omitempty"` + Scale int `xml:"scale,attr,omitempty"` + UseFirstPageNumber bool `xml:"useFirstPageNumber,attr,omitempty"` + UsePrinterDefaults bool `xml:"usePrinterDefaults,attr,omitempty"` + VerticalDPI float32 `xml:"verticalDpi,attr,omitempty"` +} + +// xlsxPrintOptions directly maps the printOptions element in the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main - Print options for +// the sheet. Printer-specific settings are stored separately in the Printer +// Settings part. +type xlsxPrintOptions struct { + GridLines bool `xml:"gridLines,attr,omitempty"` + GridLinesSet bool `xml:"gridLinesSet,attr,omitempty"` + Headings bool `xml:"headings,attr,omitempty"` + HorizontalCentered bool `xml:"horizontalCentered,attr,omitempty"` + VerticalCentered bool `xml:"verticalCentered,attr,omitempty"` +} + +// xlsxPageMargins directly maps the pageMargins element in the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main - Page margins for +// a sheet or a custom sheet view. +type xlsxPageMargins struct { + Bottom float64 `xml:"bottom,attr"` + Footer float64 `xml:"footer,attr"` + Header float64 `xml:"header,attr"` + Left float64 `xml:"left,attr"` + Right float64 `xml:"right,attr"` + Top float64 `xml:"top,attr"` +} + +// xlsxSheetFormatPr directly maps the sheetFormatPr element in the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main. This element +// specifies the sheet formatting properties. +type xlsxSheetFormatPr struct { + BaseColWidth uint8 `xml:"baseColWidth,attr,omitempty"` + DefaultColWidth float64 `xml:"defaultColWidth,attr,omitempty"` + DefaultRowHeight float64 `xml:"defaultRowHeight,attr"` + CustomHeight bool `xml:"customHeight,attr,omitempty"` + ZeroHeight bool `xml:"zeroHeight,attr,omitempty"` + ThickTop bool `xml:"thickTop,attr,omitempty"` + ThickBottom bool `xml:"thickBottom,attr,omitempty"` + OutlineLevelRow uint8 `xml:"outlineLevelRow,attr,omitempty"` + OutlineLevelCol uint8 `xml:"outlineLevelCol,attr,omitempty"` +} + +// xlsxSheetViews directly maps the sheetViews element in the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main - Worksheet views +// collection. +type xlsxSheetViews struct { + SheetView []xlsxSheetView `xml:"sheetView"` +} + +// xlsxSheetView directly maps the sheetView element in the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have +// not checked it for completeness - it does as much as I need. A single sheet +// view definition. When more than one sheet view is defined in the file, it +// means that when opening the workbook, each sheet view corresponds to a +// separate window within the spreadsheet application, where each window is +// showing the particular sheet containing the same workbookViewId value, the +// last sheetView definition is loaded, and the others are discarded. When +// multiple windows are viewing the same sheet, multiple sheetView elements +// (with corresponding workbookView entries) are saved. +// See https://msdn.microsoft.com/en-us/library/office/documentformat.openxml.spreadsheet.sheetview.aspx +type xlsxSheetView struct { + WindowProtection bool `xml:"windowProtection,attr,omitempty"` + ShowFormulas bool `xml:"showFormulas,attr,omitempty"` + ShowGridLines *bool `xml:"showGridLines,attr"` + ShowRowColHeaders *bool `xml:"showRowColHeaders,attr"` + ShowZeros bool `xml:"showZeros,attr,omitempty"` + RightToLeft bool `xml:"rightToLeft,attr,omitempty"` + TabSelected bool `xml:"tabSelected,attr,omitempty"` + ShowWhiteSpace *bool `xml:"showWhiteSpace,attr"` + ShowOutlineSymbols bool `xml:"showOutlineSymbols,attr,omitempty"` + DefaultGridColor *bool `xml:"defaultGridColor,attr"` + View string `xml:"view,attr,omitempty"` + TopLeftCell string `xml:"topLeftCell,attr,omitempty"` + ColorID int `xml:"colorId,attr,omitempty"` + ZoomScale float64 `xml:"zoomScale,attr,omitempty"` + ZoomScaleNormal float64 `xml:"zoomScaleNormal,attr,omitempty"` + ZoomScalePageLayoutView float64 `xml:"zoomScalePageLayoutView,attr,omitempty"` + ZoomScaleSheetLayoutView float64 `xml:"zoomScaleSheetLayoutView,attr,omitempty"` + WorkbookViewID int `xml:"workbookViewId,attr"` + Pane *xlsxPane `xml:"pane,omitempty"` + Selection []*xlsxSelection `xml:"selection"` +} + +// xlsxSelection directly maps the selection element in the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main - Worksheet view +// selection. +type xlsxSelection struct { + ActiveCell string `xml:"activeCell,attr,omitempty"` + ActiveCellID *int `xml:"activeCellId,attr"` + Pane string `xml:"pane,attr,omitempty"` + SQRef string `xml:"sqref,attr,omitempty"` +} + +// xlsxSelection directly maps the selection element. Worksheet view pane. +type xlsxPane struct { + ActivePane string `xml:"activePane,attr,omitempty"` + State string `xml:"state,attr,omitempty"` // Either "split" or "frozen" + TopLeftCell string `xml:"topLeftCell,attr,omitempty"` + XSplit float64 `xml:"xSplit,attr,omitempty"` + YSplit float64 `xml:"ySplit,attr,omitempty"` +} + +// xlsxSheetPr directly maps the sheetPr element in the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main - Sheet-level +// properties. +type xlsxSheetPr struct { + XMLName xml.Name `xml:"sheetPr"` + CodeName string `xml:"codeName,attr,omitempty"` + EnableFormatConditionsCalculation *bool `xml:"enableFormatConditionsCalculation,attr"` + FilterMode bool `xml:"filterMode,attr,omitempty"` + Published *bool `xml:"published,attr"` + SyncHorizontal bool `xml:"syncHorizontal,attr,omitempty"` + SyncVertical bool `xml:"syncVertical,attr,omitempty"` + TransitionEntry bool `xml:"transitionEntry,attr,omitempty"` + TabColor *xlsxTabColor `xml:"tabColor,omitempty"` + PageSetUpPr *xlsxPageSetUpPr `xml:"pageSetUpPr,omitempty"` + OutlinePr *xlsxOutlinePr `xml:"outlinePr,omitempty"` +} + +// xlsxOutlinePr maps to the outlinePr element +// SummaryBelow allows you to adjust the direction of grouper controls +type xlsxOutlinePr struct { + SummaryBelow bool `xml:"summaryBelow,attr"` +} + +// xlsxPageSetUpPr directly maps the pageSetupPr element in the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main - Page setup +// properties of the worksheet. +type xlsxPageSetUpPr struct { + AutoPageBreaks bool `xml:"autoPageBreaks,attr,omitempty"` + FitToPage bool `xml:"fitToPage,attr,omitempty"` // Flag indicating whether the Fit to Page print option is enabled. +} + +// xlsxTabColor directly maps the tabColor element in the namespace currently I +// have not checked it for completeness - it does as much as I need. +type xlsxTabColor struct { + Theme int `xml:"theme,attr,omitempty"` + Tint float64 `xml:"tint,attr,omitempty"` +} + +// xlsxCols directly maps the cols element in the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have +// not checked it for completeness - it does as much as I need. +type xlsxCols struct { + Col []xlsxCol `xml:"col"` +} + +// xlsxCol directly maps the col (Column Width & Formatting). Defines column +// width and column formatting for one or more columns of the worksheet. +type xlsxCol struct { + BestFit bool `xml:"bestFit,attr,omitempty"` + Collapsed bool `xml:"collapsed,attr"` + CustomWidth bool `xml:"customWidth,attr,omitempty"` + Hidden bool `xml:"hidden,attr"` + Max int `xml:"max,attr"` + Min int `xml:"min,attr"` + OutlineLevel uint8 `xml:"outlineLevel,attr,omitempty"` + Phonetic bool `xml:"phonetic,attr,omitempty"` + Style int `xml:"style,attr"` + Width float64 `xml:"width,attr"` +} + +// xlsxDimension directly maps the dimension element in the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main - This element +// specifies the used range of the worksheet. It specifies the row and column +// bounds of used cells in the worksheet. This is optional and is not required. +// Used cells include cells with formulas, text content, and cell formatting. +// When an entire column is formatted, only the first cell in that column is +// considered used. +type xlsxDimension struct { + Ref string `xml:"ref,attr"` +} + +// xlsxSheetData directly maps the sheetData element in the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have +// not checked it for completeness - it does as much as I need. +type xlsxSheetData struct { + XMLName xml.Name `xml:"sheetData"` + Row []xlsxRow `xml:"row"` +} + +// xlsxRow directly maps the row element. The element expresses information +// about an entire row of a worksheet, and contains all cell definitions for a +// particular row in the worksheet. +type xlsxRow struct { + Collapsed bool `xml:"collapsed,attr,omitempty"` + CustomFormat bool `xml:"customFormat,attr,omitempty"` + CustomHeight bool `xml:"customHeight,attr,omitempty"` + Hidden bool `xml:"hidden,attr,omitempty"` + Ht float64 `xml:"ht,attr,omitempty"` + OutlineLevel uint8 `xml:"outlineLevel,attr,omitempty"` + Ph bool `xml:"ph,attr,omitempty"` + R int `xml:"r,attr,omitempty"` + S int `xml:"s,attr,omitempty"` + Spans string `xml:"spans,attr,omitempty"` + ThickBot bool `xml:"thickBot,attr,omitempty"` + ThickTop bool `xml:"thickTop,attr,omitempty"` + C []xlsxC `xml:"c"` +} + +// xlsxMergeCell directly maps the mergeCell element. A single merged cell. +type xlsxMergeCell struct { + Ref string `xml:"ref,attr,omitempty"` +} + +// xlsxMergeCells directly maps the mergeCells element. This collection +// expresses all the merged cells in the sheet. +type xlsxMergeCells struct { + Count int `xml:"count,attr,omitempty"` + Cells []*xlsxMergeCell `xml:"mergeCell,omitempty"` +} + +// xlsxDataValidations expresses all data validation information for cells in a +// sheet which have data validation features applied. +type xlsxDataValidations struct { + Count int `xml:"count,attr,omitempty"` + DisablePrompts bool `xml:"disablePrompts,attr,omitempty"` + XWindow int `xml:"xWindow,attr,omitempty"` + YWindow int `xml:"yWindow,attr,omitempty"` + DataValidation []*DataValidation `xml:"dataValidation"` +} + +// DataValidation directly maps the a single item of data validation defined +// on a range of the worksheet. +type DataValidation struct { + AllowBlank bool `xml:"allowBlank,attr"` + Error *string `xml:"error,attr"` + ErrorStyle *string `xml:"errorStyle,attr"` + ErrorTitle *string `xml:"errorTitle,attr"` + Operator string `xml:"operator,attr"` + Prompt *string `xml:"prompt,attr"` + PromptTitle *string `xml:"promptTitle"` + ShowDropDown bool `xml:"showDropDown,attr"` + ShowErrorMessage bool `xml:"showErrorMessage,attr"` + ShowInputMessage bool `xml:"showInputMessage,attr"` + Sqref string `xml:"sqref,attr"` + Type string `xml:"type,attr"` + Formula1 string `xml:"formula1"` + Formula2 string `xml:"formula2"` +} + +// xlsxC directly maps the c element in the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have +// not checked it for completeness - it does as much as I need. +// +// This simple type is restricted to the values listed in the following table: +// +// Enumeration Value | Description +// ---------------------------+--------------------------------- +// b (Boolean) | Cell containing a boolean. +// d (Date) | Cell contains a date in the ISO 8601 format. +// e (Error) | Cell containing an error. +// inlineStr (Inline String) | Cell containing an (inline) rich string, i.e., one not in the shared string table. If this cell type is used, then the cell value is in the is element rather than the v element in the cell (c element). +// n (Number) | Cell containing a number. +// s (Shared String) | Cell containing a shared string. +// str (String) | Cell containing a formula string. +// +type xlsxC struct { + R string `xml:"r,attr"` // Cell ID, e.g. A1 + S int `xml:"s,attr,omitempty"` // Style reference. + // Str string `xml:"str,attr,omitempty"` // Style reference. + T string `xml:"t,attr,omitempty"` // Type. + F *xlsxF `xml:"f,omitempty"` // Formula + V string `xml:"v,omitempty"` // Value + IS *xlsxIS `xml:"is"` + XMLSpace xml.Attr `xml:"space,attr,omitempty"` +} + +// xlsxIS directly maps the t element. Cell containing an (inline) rich +// string, i.e., one not in the shared string table. If this cell type is +// used, then the cell value is in the is element rather than the v element in +// the cell (c element). +type xlsxIS struct { + T string `xml:"t"` +} + +// xlsxF directly maps the f element in the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have +// not checked it for completeness - it does as much as I need. +type xlsxF struct { + Content string `xml:",chardata"` + T string `xml:"t,attr,omitempty"` // Formula type + Ref string `xml:"ref,attr,omitempty"` // Shared formula ref + Si string `xml:"si,attr,omitempty"` // Shared formula index +} + +// xlsxSheetProtection collection expresses the sheet protection options to +// enforce when the sheet is protected. +type xlsxSheetProtection struct { + AlgorithmName string `xml:"algorithmName,attr,omitempty"` + AutoFilter bool `xml:"autoFilter,attr,omitempty"` + DeleteColumns bool `xml:"deleteColumns,attr,omitempty"` + DeleteRows bool `xml:"deleteRows,attr,omitempty"` + FormatCells bool `xml:"formatCells,attr,omitempty"` + FormatColumns bool `xml:"formatColumns,attr,omitempty"` + FormatRows bool `xml:"formatRows,attr,omitempty"` + HashValue string `xml:"hashValue,attr,omitempty"` + InsertColumns bool `xml:"insertColumns,attr,omitempty"` + InsertHyperlinks bool `xml:"insertHyperlinks,attr,omitempty"` + InsertRows bool `xml:"insertRows,attr,omitempty"` + Objects bool `xml:"objects,attr,omitempty"` + Password string `xml:"password,attr,omitempty"` + PivotTables bool `xml:"pivotTables,attr,omitempty"` + SaltValue string `xml:"saltValue,attr,omitempty"` + Scenarios bool `xml:"scenarios,attr,omitempty"` + SelectLockedCells bool `xml:"selectLockedCells,attr,omitempty"` + SelectUnlockedCells bool `xml:"selectUnlockedCells,attr,omitempty"` + Sheet bool `xml:"sheet,attr,omitempty"` + Sort bool `xml:"sort,attr,omitempty"` + SpinCount int `xml:"spinCount,attr,omitempty"` +} + +// xlsxPhoneticPr (Phonetic Properties) represents a collection of phonetic +// properties that affect the display of phonetic text for this String Item +// (si). Phonetic text is used to give hints as to the pronunciation of an East +// Asian language, and the hints are displayed as text within the spreadsheet +// cells across the top portion of the cell. Since the phonetic hints are text, +// every phonetic hint is expressed as a phonetic run (rPh), and these +// properties specify how to display that phonetic run. +type xlsxPhoneticPr struct { + Alignment string `xml:"alignment,attr,omitempty"` + FontID *int `xml:"fontId,attr"` + Type string `xml:"type,attr,omitempty"` +} + +// A Conditional Format is a format, such as cell shading or font color, that a +// spreadsheet application can automatically apply to cells if a specified +// condition is true. This collection expresses conditional formatting rules +// applied to a particular cell or range. +type xlsxConditionalFormatting struct { + SQRef string `xml:"sqref,attr,omitempty"` + CfRule []*xlsxCfRule `xml:"cfRule"` +} + +// xlsxCfRule (Conditional Formatting Rule) represents a description of a +// conditional formatting rule. +type xlsxCfRule struct { + AboveAverage *bool `xml:"aboveAverage,attr"` + Bottom bool `xml:"bottom,attr,omitempty"` + DxfID *int `xml:"dxfId,attr"` + EqualAverage bool `xml:"equalAverage,attr,omitempty"` + Operator string `xml:"operator,attr,omitempty"` + Percent bool `xml:"percent,attr,omitempty"` + Priority int `xml:"priority,attr,omitempty"` + Rank int `xml:"rank,attr,omitempty"` + StdDev int `xml:"stdDev,attr,omitempty"` + StopIfTrue bool `xml:"stopIfTrue,attr,omitempty"` + Text string `xml:"text,attr,omitempty"` + TimePeriod string `xml:"timePeriod,attr,omitempty"` + Type string `xml:"type,attr,omitempty"` + Formula []string `xml:"formula,omitempty"` + ColorScale *xlsxColorScale `xml:"colorScale"` + DataBar *xlsxDataBar `xml:"dataBar"` + IconSet *xlsxIconSet `xml:"iconSet"` + ExtLst *xlsxExtLst `xml:"extLst"` +} + +// xlsxColorScale (Color Scale) describes a gradated color scale in this +// conditional formatting rule. +type xlsxColorScale struct { + Cfvo []*xlsxCfvo `xml:"cfvo"` + Color []*xlsxColor `xml:"color"` +} + +// dataBar (Data Bar) describes a data bar conditional formatting rule. +type xlsxDataBar struct { + MaxLength int `xml:"maxLength,attr,omitempty"` + MinLength int `xml:"minLength,attr,omitempty"` + ShowValue bool `xml:"showValue,attr,omitempty"` + Cfvo []*xlsxCfvo `xml:"cfvo"` + Color []*xlsxColor `xml:"color"` +} + +// xlsxIconSet (Icon Set) describes an icon set conditional formatting rule. +type xlsxIconSet struct { + Cfvo []*xlsxCfvo `xml:"cfvo"` + IconSet string `xml:"iconSet,attr,omitempty"` + ShowValue bool `xml:"showValue,attr,omitempty"` + Percent bool `xml:"percent,attr,omitempty"` + Reverse bool `xml:"reverse,attr,omitempty"` +} + +// cfvo (Conditional Format Value Object) describes the values of the +// interpolation points in a gradient scale. +type xlsxCfvo struct { + Gte bool `xml:"gte,attr,omitempty"` + Type string `xml:"type,attr,omitempty"` + Val string `xml:"val,attr"` + ExtLst *xlsxExtLst `xml:"extLst"` +} + +// xlsxHyperlinks directly maps the hyperlinks element in the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main - A hyperlink can +// be stored in a package as a relationship. Hyperlinks shall be identified by +// containing a target which specifies the destination of the given hyperlink. +type xlsxHyperlinks struct { + Hyperlink []xlsxHyperlink `xml:"hyperlink"` +} + +// xlsxHyperlink directly maps the hyperlink element in the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main +type xlsxHyperlink struct { + Ref string `xml:"ref,attr"` + Location string `xml:"location,attr,omitempty"` + Display string `xml:"display,attr,omitempty"` + RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"` +} + +// xlsxTableParts directly maps the tableParts element in the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main - The table element +// has several attributes applied to identify the table and the data range it +// covers. The table id attribute needs to be unique across all table parts, the +// same goes for the name and displayName. The displayName has the further +// restriction that it must be unique across all defined names in the workbook. +// Later on we will see that you can define names for many elements, such as +// cells or formulas. The name value is used for the object model in Microsoft +// Office Excel. The displayName is used for references in formulas. The ref +// attribute is used to identify the cell range that the table covers. This +// includes not only the table data, but also the table header containing column +// names. +// To add columns to your table you add new tableColumn elements to the +// tableColumns container. Similar to the shared string table the collection +// keeps a count attribute identifying the number of columns. Besides the table +// definition in the table part there is also the need to identify which tables +// are displayed in the worksheet. The worksheet part has a separate element +// tableParts to store this information. Each table part is referenced through +// the relationship ID and again a count of the number of table parts is +// maintained. The following markup sample is taken from the documents +// accompanying this book. The sheet data element has been removed to reduce the +// size of the sample. To reference the table, just add the tableParts element, +// of course after having created and stored the table part. For example: +// +// +// ... +// +// +// +// +// +type xlsxTableParts struct { + Count int `xml:"count,attr,omitempty"` + TableParts []*xlsxTablePart `xml:"tablePart"` +} + +// xlsxTablePart directly maps the tablePart element in the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main +type xlsxTablePart struct { + RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"` +} + +// xlsxPicture directly maps the picture element in the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main - Background sheet +// image. For example: +// +// +// +type xlsxPicture struct { + RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"` +} + +// xlsxLegacyDrawing directly maps the legacyDrawing element in the namespace +// http://schemas.openxmlformats.org/spreadsheetml/2006/main - A comment is a +// rich text note that is attached to, and associated with, a cell, separate +// from other cell content. Comment content is stored separate from the cell, +// and is displayed in a drawing object (like a text box) that is separate from, +// but associated with, a cell. Comments are used as reminders, such as noting +// how a complex formula works, or to provide feedback to other users. Comments +// can also be used to explain assumptions made in a formula or to call out +// something special about the cell. +type xlsxLegacyDrawing struct { + RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"` +} + +// formatPanes directly maps the settings of the panes. +type formatPanes struct { + Freeze bool `json:"freeze"` + Split bool `json:"split"` + XSplit int `json:"x_split"` + YSplit int `json:"y_split"` + TopLeftCell string `json:"top_left_cell"` + ActivePane string `json:"active_pane"` + Panes []struct { + SQRef string `json:"sqref"` + ActiveCell string `json:"active_cell"` + Pane string `json:"pane"` + } `json:"panes"` +} + +// formatConditional directly maps the conditional format settings of the cells. +type formatConditional struct { + Type string `json:"type"` + AboveAverage bool `json:"above_average"` + Percent bool `json:"percent"` + Format int `json:"format"` + Criteria string `json:"criteria"` + Value string `json:"value,omitempty"` + Minimum string `json:"minimum,omitempty"` + Maximum string `json:"maximum,omitempty"` + MinType string `json:"min_type,omitempty"` + MidType string `json:"mid_type,omitempty"` + MaxType string `json:"max_type,omitempty"` + MinValue string `json:"min_value,omitempty"` + MidValue string `json:"mid_value,omitempty"` + MaxValue string `json:"max_value,omitempty"` + MinColor string `json:"min_color,omitempty"` + MidColor string `json:"mid_color,omitempty"` + MaxColor string `json:"max_color,omitempty"` + MinLength string `json:"min_length,omitempty"` + MaxLength string `json:"max_length,omitempty"` + MultiRange string `json:"multi_range,omitempty"` + BarColor string `json:"bar_color,omitempty"` +} + +// FormatSheetProtection directly maps the settings of worksheet protection. +type FormatSheetProtection struct { + AutoFilter bool + DeleteColumns bool + DeleteRows bool + EditObjects bool + EditScenarios bool + FormatCells bool + FormatColumns bool + FormatRows bool + InsertColumns bool + InsertHyperlinks bool + InsertRows bool + Password string + PivotTables bool + SelectLockedCells bool + SelectUnlockedCells bool + Sort bool +} diff --git a/vendor/github.com/mohae/deepcopy/.gitignore b/vendor/github.com/mohae/deepcopy/.gitignore new file mode 100644 index 0000000000..5846dd1531 --- /dev/null +++ b/vendor/github.com/mohae/deepcopy/.gitignore @@ -0,0 +1,26 @@ +# Compiled Object files, Static and Dynamic libs (Shared Objects) +*.o +*.a +*.so + +# Folders +_obj +_test + +# Architecture specific extensions/prefixes +*.[568vq] +[568vq].out + +*.cgo1.go +*.cgo2.c +_cgo_defun.c +_cgo_gotypes.go +_cgo_export.* + +_testmain.go + +*.exe +*.test +*~ +*.out +*.log diff --git a/vendor/github.com/mohae/deepcopy/.travis.yml b/vendor/github.com/mohae/deepcopy/.travis.yml new file mode 100644 index 0000000000..fd47a8cf78 --- /dev/null +++ b/vendor/github.com/mohae/deepcopy/.travis.yml @@ -0,0 +1,11 @@ +language: go + +go: + - tip + +matrix: + allow_failures: + - go: tip + +script: + - go test ./... diff --git a/vendor/github.com/mohae/deepcopy/LICENSE b/vendor/github.com/mohae/deepcopy/LICENSE new file mode 100644 index 0000000000..419673f005 --- /dev/null +++ b/vendor/github.com/mohae/deepcopy/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 Joel + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/github.com/mohae/deepcopy/README.md b/vendor/github.com/mohae/deepcopy/README.md new file mode 100644 index 0000000000..f81841885b --- /dev/null +++ b/vendor/github.com/mohae/deepcopy/README.md @@ -0,0 +1,8 @@ +deepCopy +======== +[![GoDoc](https://godoc.org/github.com/mohae/deepcopy?status.svg)](https://godoc.org/github.com/mohae/deepcopy)[![Build Status](https://travis-ci.org/mohae/deepcopy.png)](https://travis-ci.org/mohae/deepcopy) + +DeepCopy makes deep copies of things: unexported field values are not copied. + +## Usage + cpy := deepcopy.Copy(orig) diff --git a/vendor/github.com/mohae/deepcopy/deepcopy.go b/vendor/github.com/mohae/deepcopy/deepcopy.go new file mode 100644 index 0000000000..ba763ad091 --- /dev/null +++ b/vendor/github.com/mohae/deepcopy/deepcopy.go @@ -0,0 +1,125 @@ +// deepcopy makes deep copies of things. A standard copy will copy the +// pointers: deep copy copies the values pointed to. Unexported field +// values are not copied. +// +// Copyright (c)2014-2016, Joel Scoble (github.com/mohae), all rights reserved. +// License: MIT, for more details check the included LICENSE file. +package deepcopy + +import ( + "reflect" + "time" +) + +// Interface for delegating copy process to type +type Interface interface { + DeepCopy() interface{} +} + +// Iface is an alias to Copy; this exists for backwards compatibility reasons. +func Iface(iface interface{}) interface{} { + return Copy(iface) +} + +// Copy creates a deep copy of whatever is passed to it and returns the copy +// in an interface{}. The returned value will need to be asserted to the +// correct type. +func Copy(src interface{}) interface{} { + if src == nil { + return nil + } + + // Make the interface a reflect.Value + original := reflect.ValueOf(src) + + // Make a copy of the same type as the original. + cpy := reflect.New(original.Type()).Elem() + + // Recursively copy the original. + copyRecursive(original, cpy) + + // Return the copy as an interface. + return cpy.Interface() +} + +// copyRecursive does the actual copying of the interface. It currently has +// limited support for what it can handle. Add as needed. +func copyRecursive(original, cpy reflect.Value) { + // check for implement deepcopy.Interface + if original.CanInterface() { + if copier, ok := original.Interface().(Interface); ok { + cpy.Set(reflect.ValueOf(copier.DeepCopy())) + return + } + } + + // handle according to original's Kind + switch original.Kind() { + case reflect.Ptr: + // Get the actual value being pointed to. + originalValue := original.Elem() + + // if it isn't valid, return. + if !originalValue.IsValid() { + return + } + cpy.Set(reflect.New(originalValue.Type())) + copyRecursive(originalValue, cpy.Elem()) + + case reflect.Interface: + // If this is a nil, don't do anything + if original.IsNil() { + return + } + // Get the value for the interface, not the pointer. + originalValue := original.Elem() + + // Get the value by calling Elem(). + copyValue := reflect.New(originalValue.Type()).Elem() + copyRecursive(originalValue, copyValue) + cpy.Set(copyValue) + + case reflect.Struct: + t, ok := original.Interface().(time.Time) + if ok { + cpy.Set(reflect.ValueOf(t)) + return + } + // Go through each field of the struct and copy it. + for i := 0; i < original.NumField(); i++ { + // The Type's StructField for a given field is checked to see if StructField.PkgPath + // is set to determine if the field is exported or not because CanSet() returns false + // for settable fields. I'm not sure why. -mohae + if original.Type().Field(i).PkgPath != "" { + continue + } + copyRecursive(original.Field(i), cpy.Field(i)) + } + + case reflect.Slice: + if original.IsNil() { + return + } + // Make a new slice and copy each element. + cpy.Set(reflect.MakeSlice(original.Type(), original.Len(), original.Cap())) + for i := 0; i < original.Len(); i++ { + copyRecursive(original.Index(i), cpy.Index(i)) + } + + case reflect.Map: + if original.IsNil() { + return + } + cpy.Set(reflect.MakeMap(original.Type())) + for _, key := range original.MapKeys() { + originalValue := original.MapIndex(key) + copyValue := reflect.New(originalValue.Type()).Elem() + copyRecursive(originalValue, copyValue) + copyKey := Copy(key.Interface()) + cpy.SetMapIndex(reflect.ValueOf(copyKey), copyValue) + } + + default: + cpy.Set(original) + } +} diff --git a/vendor/github.com/pjbgf/sha1cd/cgo/sha1.c b/vendor/github.com/pjbgf/sha1cd/cgo/sha1.c deleted file mode 100644 index f532ef0e4d..0000000000 --- a/vendor/github.com/pjbgf/sha1cd/cgo/sha1.c +++ /dev/null @@ -1,2144 +0,0 @@ -/*** - * Copyright 2017 Marc Stevens , Dan Shumow (danshu@microsoft.com) - * Distributed under the MIT Software License. - * See accompanying file LICENSE.txt or copy at - * https://opensource.org/licenses/MIT - ***/ - -// Originally from: https://github.com/cr-marcstevens/sha1collisiondetection - -#ifndef SHA1DC_NO_STANDARD_INCLUDES -#include -#include -#include -#include -#ifdef __unix__ -#include /* make sure macros like _BIG_ENDIAN visible */ -#endif -#endif - -#ifdef SHA1DC_CUSTOM_INCLUDE_SHA1_C -#include SHA1DC_CUSTOM_INCLUDE_SHA1_C -#endif - -#ifndef SHA1DC_INIT_SAFE_HASH_DEFAULT -#define SHA1DC_INIT_SAFE_HASH_DEFAULT 1 -#endif - -#include "sha1.h" -#include "ubc_check.h" - -#if (defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || \ - defined(i386) || defined(__i386) || defined(__i386__) || defined(__i486__) || \ - defined(__i586__) || defined(__i686__) || defined(_M_IX86) || defined(__X86__) || \ - defined(_X86_) || defined(__THW_INTEL__) || defined(__I86__) || defined(__INTEL__) || \ - defined(__386) || defined(_M_X64) || defined(_M_AMD64)) -#define SHA1DC_ON_INTEL_LIKE_PROCESSOR -#endif - -/* - Because Little-Endian architectures are most common, - we only set SHA1DC_BIGENDIAN if one of these conditions is met. - Note that all MSFT platforms are little endian, - so none of these will be defined under the MSC compiler. - If you are compiling on a big endian platform and your compiler does not define one of these, - you will have to add whatever macros your tool chain defines to indicate Big-Endianness. - */ - -#if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) -/* - * Should detect Big Endian under GCC since at least 4.6.0 (gcc svn - * rev #165881). See - * https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html - * - * This also works under clang since 3.2, it copied the GCC-ism. See - * clang.git's 3b198a97d2 ("Preprocessor: add __BYTE_ORDER__ - * predefined macro", 2012-07-27) - */ -#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -#define SHA1DC_BIGENDIAN -#endif - -/* Not under GCC-alike */ -#elif defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) -/* - * Should detect Big Endian under glibc.git since 14245eb70e ("entered - * into RCS", 1992-11-25). Defined in which will have been - * brought in by standard headers. See glibc.git and - * https://sourceforge.net/p/predef/wiki/Endianness/ - */ -#if __BYTE_ORDER == __BIG_ENDIAN -#define SHA1DC_BIGENDIAN -#endif - -/* Not under GCC-alike or glibc */ -#elif defined(_BYTE_ORDER) && defined(_BIG_ENDIAN) && defined(_LITTLE_ENDIAN) -/* - * *BSD and newlib (embedded linux, cygwin, etc). - * the defined(_BIG_ENDIAN) && defined(_LITTLE_ENDIAN) part prevents - * this condition from matching with Solaris/sparc. - * (Solaris defines only one endian macro) - */ -#if _BYTE_ORDER == _BIG_ENDIAN -#define SHA1DC_BIGENDIAN -#endif - -/* Not under GCC-alike or glibc or *BSD or newlib */ -#elif (defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \ - defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || \ - defined(__sparc)) -/* - * Should define Big Endian for a whitelist of known processors. See - * https://sourceforge.net/p/predef/wiki/Endianness/ and - * http://www.oracle.com/technetwork/server-storage/solaris/portingtosolaris-138514.html - */ -#define SHA1DC_BIGENDIAN - -/* Not under GCC-alike or glibc or *BSD or newlib or */ -#elif (defined(_AIX) || defined(__hpux)) - -/* - * Defines Big Endian on a whitelist of OSs that are known to be Big - * Endian-only. See - * https://public-inbox.org/git/93056823-2740-d072-1ebd-46b440b33d7e@felt.demon.nl/ - */ -#define SHA1DC_BIGENDIAN - -/* Not under GCC-alike or glibc or *BSD or newlib or or */ -#elif defined(SHA1DC_ON_INTEL_LIKE_PROCESSOR) -/* - * As a last resort before we do anything else we're not 100% sure - * about below, we blacklist specific processors here. We could add - * more, see e.g. https://wiki.debian.org/ArchitectureSpecificsMemo - */ -#else /* Not under GCC-alike or glibc or *BSD or newlib or or or */ - -/* We do nothing more here for now */ -/*#error "Uncomment this to see if you fall through all the detection"*/ - -#endif /* Big Endian detection */ - -#if (defined(SHA1DC_FORCE_LITTLEENDIAN) && defined(SHA1DC_BIGENDIAN)) -#undef SHA1DC_BIGENDIAN -#endif -#if (defined(SHA1DC_FORCE_BIGENDIAN) && !defined(SHA1DC_BIGENDIAN)) -#define SHA1DC_BIGENDIAN -#endif -/*ENDIANNESS SELECTION*/ - -#ifndef SHA1DC_FORCE_ALIGNED_ACCESS -#if defined(SHA1DC_FORCE_UNALIGNED_ACCESS) || defined(SHA1DC_ON_INTEL_LIKE_PROCESSOR) -#define SHA1DC_ALLOW_UNALIGNED_ACCESS -#endif /*UNALIGNED ACCESS DETECTION*/ -#endif /*FORCE ALIGNED ACCESS*/ - -#define rotate_right(x, n) (((x) >> (n)) | ((x) << (32 - (n)))) -#define rotate_left(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) - -#define sha1_bswap32(x) \ - { \ - x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); \ - x = (x << 16) | (x >> 16); \ - } - -#define sha1_mix(W, t) (rotate_left(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1)) - -#ifdef SHA1DC_BIGENDIAN -#define sha1_load(m, t, temp) \ - { \ - temp = m[t]; \ - } -#else -#define sha1_load(m, t, temp) \ - { \ - temp = m[t]; \ - sha1_bswap32(temp); \ - } -#endif - -#define sha1_store(W, t, x) *(volatile uint32_t *)&W[t] = x - -#define sha1_f1(b, c, d) ((d) ^ ((b) & ((c) ^ (d)))) -#define sha1_f2(b, c, d) ((b) ^ (c) ^ (d)) -#define sha1_f3(b, c, d) (((b) & (c)) + ((d) & ((b) ^ (c)))) -#define sha1_f4(b, c, d) ((b) ^ (c) ^ (d)) - -#define HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, m, t) \ - { \ - e += rotate_left(a, 5) + sha1_f1(b, c, d) + 0x5A827999 + m[t]; \ - b = rotate_left(b, 30); \ - } -#define HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, m, t) \ - { \ - e += rotate_left(a, 5) + sha1_f2(b, c, d) + 0x6ED9EBA1 + m[t]; \ - b = rotate_left(b, 30); \ - } -#define HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, m, t) \ - { \ - e += rotate_left(a, 5) + sha1_f3(b, c, d) + 0x8F1BBCDC + m[t]; \ - b = rotate_left(b, 30); \ - } -#define HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, m, t) \ - { \ - e += rotate_left(a, 5) + sha1_f4(b, c, d) + 0xCA62C1D6 + m[t]; \ - b = rotate_left(b, 30); \ - } - -#define HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, m, t) \ - { \ - b = rotate_right(b, 30); \ - e -= rotate_left(a, 5) + sha1_f1(b, c, d) + 0x5A827999 + m[t]; \ - } -#define HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, m, t) \ - { \ - b = rotate_right(b, 30); \ - e -= rotate_left(a, 5) + sha1_f2(b, c, d) + 0x6ED9EBA1 + m[t]; \ - } -#define HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, m, t) \ - { \ - b = rotate_right(b, 30); \ - e -= rotate_left(a, 5) + sha1_f3(b, c, d) + 0x8F1BBCDC + m[t]; \ - } -#define HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, m, t) \ - { \ - b = rotate_right(b, 30); \ - e -= rotate_left(a, 5) + sha1_f4(b, c, d) + 0xCA62C1D6 + m[t]; \ - } - -#define SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, t, temp) \ - { \ - sha1_load(m, t, temp); \ - sha1_store(W, t, temp); \ - e += temp + rotate_left(a, 5) + sha1_f1(b, c, d) + 0x5A827999; \ - b = rotate_left(b, 30); \ - } - -#define SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(a, b, c, d, e, W, t, temp) \ - { \ - temp = sha1_mix(W, t); \ - sha1_store(W, t, temp); \ - e += temp + rotate_left(a, 5) + sha1_f1(b, c, d) + 0x5A827999; \ - b = rotate_left(b, 30); \ - } - -#define SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, t, temp) \ - { \ - temp = sha1_mix(W, t); \ - sha1_store(W, t, temp); \ - e += temp + rotate_left(a, 5) + sha1_f2(b, c, d) + 0x6ED9EBA1; \ - b = rotate_left(b, 30); \ - } - -#define SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, t, temp) \ - { \ - temp = sha1_mix(W, t); \ - sha1_store(W, t, temp); \ - e += temp + rotate_left(a, 5) + sha1_f3(b, c, d) + 0x8F1BBCDC; \ - b = rotate_left(b, 30); \ - } - -#define SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, t, temp) \ - { \ - temp = sha1_mix(W, t); \ - sha1_store(W, t, temp); \ - e += temp + rotate_left(a, 5) + sha1_f4(b, c, d) + 0xCA62C1D6; \ - b = rotate_left(b, 30); \ - } - -#define SHA1_STORE_STATE(i) \ - states[i][0] = a; \ - states[i][1] = b; \ - states[i][2] = c; \ - states[i][3] = d; \ - states[i][4] = e; - -#ifdef BUILDNOCOLLDETECTSHA1COMPRESSION -void sha1_compression(uint32_t ihv[5], const uint32_t m[16]) -{ - uint32_t W[80]; - uint32_t a, b, c, d, e; - unsigned i; - - memcpy(W, m, 16 * 4); - for (i = 16; i < 80; ++i) - W[i] = sha1_mix(W, i); - - a = ihv[0]; - b = ihv[1]; - c = ihv[2]; - d = ihv[3]; - e = ihv[4]; - - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 0); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 1); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 2); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 3); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 4); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 5); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 6); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 7); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 8); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 9); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 10); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 11); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 12); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 13); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 14); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 15); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 16); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 17); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 18); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 19); - - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 20); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 21); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 22); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 23); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 24); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 25); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 26); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 27); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 28); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 29); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 30); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 31); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 32); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 33); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 34); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 35); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 36); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 37); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 38); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 39); - - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 40); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 41); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 42); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 43); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 44); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 45); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 46); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 47); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 48); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 49); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 50); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 51); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 52); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 53); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 54); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 55); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 56); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 57); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 58); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 59); - - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 60); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 61); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 62); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 63); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 64); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 65); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 66); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 67); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 68); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 69); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 70); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 71); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 72); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 73); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 74); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 75); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 76); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 77); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 78); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 79); - - ihv[0] += a; - ihv[1] += b; - ihv[2] += c; - ihv[3] += d; - ihv[4] += e; -} -#endif /*BUILDNOCOLLDETECTSHA1COMPRESSION*/ - -static void sha1_compression_W(uint32_t ihv[5], const uint32_t W[80]) -{ - uint32_t a = ihv[0], b = ihv[1], c = ihv[2], d = ihv[3], e = ihv[4]; - - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 0); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 1); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 2); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 3); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 4); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 5); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 6); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 7); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 8); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 9); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 10); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 11); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 12); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 13); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 14); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 15); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 16); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 17); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 18); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 19); - - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 20); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 21); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 22); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 23); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 24); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 25); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 26); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 27); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 28); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 29); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 30); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 31); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 32); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 33); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 34); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 35); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 36); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 37); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 38); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 39); - - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 40); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 41); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 42); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 43); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 44); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 45); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 46); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 47); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 48); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 49); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 50); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 51); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 52); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 53); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 54); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 55); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 56); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 57); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 58); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 59); - - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 60); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 61); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 62); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 63); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 64); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 65); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 66); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 67); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 68); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 69); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 70); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 71); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 72); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 73); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 74); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 75); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 76); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 77); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 78); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 79); - - ihv[0] += a; - ihv[1] += b; - ihv[2] += c; - ihv[3] += d; - ihv[4] += e; -} - -void sha1_compression_states(uint32_t ihv[5], const uint32_t m[16], uint32_t W[80], uint32_t states[80][5]) -{ - uint32_t a = ihv[0], b = ihv[1], c = ihv[2], d = ihv[3], e = ihv[4]; - uint32_t temp; - -#ifdef DOSTORESTATE00 - SHA1_STORE_STATE(0) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, 0, temp); - -#ifdef DOSTORESTATE01 - SHA1_STORE_STATE(1) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(e, a, b, c, d, m, W, 1, temp); - -#ifdef DOSTORESTATE02 - SHA1_STORE_STATE(2) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(d, e, a, b, c, m, W, 2, temp); - -#ifdef DOSTORESTATE03 - SHA1_STORE_STATE(3) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(c, d, e, a, b, m, W, 3, temp); - -#ifdef DOSTORESTATE04 - SHA1_STORE_STATE(4) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(b, c, d, e, a, m, W, 4, temp); - -#ifdef DOSTORESTATE05 - SHA1_STORE_STATE(5) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, 5, temp); - -#ifdef DOSTORESTATE06 - SHA1_STORE_STATE(6) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(e, a, b, c, d, m, W, 6, temp); - -#ifdef DOSTORESTATE07 - SHA1_STORE_STATE(7) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(d, e, a, b, c, m, W, 7, temp); - -#ifdef DOSTORESTATE08 - SHA1_STORE_STATE(8) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(c, d, e, a, b, m, W, 8, temp); - -#ifdef DOSTORESTATE09 - SHA1_STORE_STATE(9) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(b, c, d, e, a, m, W, 9, temp); - -#ifdef DOSTORESTATE10 - SHA1_STORE_STATE(10) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, 10, temp); - -#ifdef DOSTORESTATE11 - SHA1_STORE_STATE(11) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(e, a, b, c, d, m, W, 11, temp); - -#ifdef DOSTORESTATE12 - SHA1_STORE_STATE(12) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(d, e, a, b, c, m, W, 12, temp); - -#ifdef DOSTORESTATE13 - SHA1_STORE_STATE(13) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(c, d, e, a, b, m, W, 13, temp); - -#ifdef DOSTORESTATE14 - SHA1_STORE_STATE(14) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(b, c, d, e, a, m, W, 14, temp); - -#ifdef DOSTORESTATE15 - SHA1_STORE_STATE(15) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, 15, temp); - -#ifdef DOSTORESTATE16 - SHA1_STORE_STATE(16) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(e, a, b, c, d, W, 16, temp); - -#ifdef DOSTORESTATE17 - SHA1_STORE_STATE(17) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(d, e, a, b, c, W, 17, temp); - -#ifdef DOSTORESTATE18 - SHA1_STORE_STATE(18) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(c, d, e, a, b, W, 18, temp); - -#ifdef DOSTORESTATE19 - SHA1_STORE_STATE(19) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(b, c, d, e, a, W, 19, temp); - -#ifdef DOSTORESTATE20 - SHA1_STORE_STATE(20) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, 20, temp); - -#ifdef DOSTORESTATE21 - SHA1_STORE_STATE(21) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(e, a, b, c, d, W, 21, temp); - -#ifdef DOSTORESTATE22 - SHA1_STORE_STATE(22) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(d, e, a, b, c, W, 22, temp); - -#ifdef DOSTORESTATE23 - SHA1_STORE_STATE(23) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(c, d, e, a, b, W, 23, temp); - -#ifdef DOSTORESTATE24 - SHA1_STORE_STATE(24) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(b, c, d, e, a, W, 24, temp); - -#ifdef DOSTORESTATE25 - SHA1_STORE_STATE(25) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, 25, temp); - -#ifdef DOSTORESTATE26 - SHA1_STORE_STATE(26) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(e, a, b, c, d, W, 26, temp); - -#ifdef DOSTORESTATE27 - SHA1_STORE_STATE(27) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(d, e, a, b, c, W, 27, temp); - -#ifdef DOSTORESTATE28 - SHA1_STORE_STATE(28) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(c, d, e, a, b, W, 28, temp); - -#ifdef DOSTORESTATE29 - SHA1_STORE_STATE(29) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(b, c, d, e, a, W, 29, temp); - -#ifdef DOSTORESTATE30 - SHA1_STORE_STATE(30) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, 30, temp); - -#ifdef DOSTORESTATE31 - SHA1_STORE_STATE(31) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(e, a, b, c, d, W, 31, temp); - -#ifdef DOSTORESTATE32 - SHA1_STORE_STATE(32) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(d, e, a, b, c, W, 32, temp); - -#ifdef DOSTORESTATE33 - SHA1_STORE_STATE(33) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(c, d, e, a, b, W, 33, temp); - -#ifdef DOSTORESTATE34 - SHA1_STORE_STATE(34) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(b, c, d, e, a, W, 34, temp); - -#ifdef DOSTORESTATE35 - SHA1_STORE_STATE(35) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, 35, temp); - -#ifdef DOSTORESTATE36 - SHA1_STORE_STATE(36) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(e, a, b, c, d, W, 36, temp); - -#ifdef DOSTORESTATE37 - SHA1_STORE_STATE(37) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(d, e, a, b, c, W, 37, temp); - -#ifdef DOSTORESTATE38 - SHA1_STORE_STATE(38) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(c, d, e, a, b, W, 38, temp); - -#ifdef DOSTORESTATE39 - SHA1_STORE_STATE(39) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(b, c, d, e, a, W, 39, temp); - -#ifdef DOSTORESTATE40 - SHA1_STORE_STATE(40) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, 40, temp); - -#ifdef DOSTORESTATE41 - SHA1_STORE_STATE(41) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(e, a, b, c, d, W, 41, temp); - -#ifdef DOSTORESTATE42 - SHA1_STORE_STATE(42) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(d, e, a, b, c, W, 42, temp); - -#ifdef DOSTORESTATE43 - SHA1_STORE_STATE(43) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(c, d, e, a, b, W, 43, temp); - -#ifdef DOSTORESTATE44 - SHA1_STORE_STATE(44) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(b, c, d, e, a, W, 44, temp); - -#ifdef DOSTORESTATE45 - SHA1_STORE_STATE(45) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, 45, temp); - -#ifdef DOSTORESTATE46 - SHA1_STORE_STATE(46) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(e, a, b, c, d, W, 46, temp); - -#ifdef DOSTORESTATE47 - SHA1_STORE_STATE(47) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(d, e, a, b, c, W, 47, temp); - -#ifdef DOSTORESTATE48 - SHA1_STORE_STATE(48) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(c, d, e, a, b, W, 48, temp); - -#ifdef DOSTORESTATE49 - SHA1_STORE_STATE(49) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(b, c, d, e, a, W, 49, temp); - -#ifdef DOSTORESTATE50 - SHA1_STORE_STATE(50) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, 50, temp); - -#ifdef DOSTORESTATE51 - SHA1_STORE_STATE(51) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(e, a, b, c, d, W, 51, temp); - -#ifdef DOSTORESTATE52 - SHA1_STORE_STATE(52) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(d, e, a, b, c, W, 52, temp); - -#ifdef DOSTORESTATE53 - SHA1_STORE_STATE(53) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(c, d, e, a, b, W, 53, temp); - -#ifdef DOSTORESTATE54 - SHA1_STORE_STATE(54) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(b, c, d, e, a, W, 54, temp); - -#ifdef DOSTORESTATE55 - SHA1_STORE_STATE(55) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, 55, temp); - -#ifdef DOSTORESTATE56 - SHA1_STORE_STATE(56) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(e, a, b, c, d, W, 56, temp); - -#ifdef DOSTORESTATE57 - SHA1_STORE_STATE(57) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(d, e, a, b, c, W, 57, temp); - -#ifdef DOSTORESTATE58 - SHA1_STORE_STATE(58) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(c, d, e, a, b, W, 58, temp); - -#ifdef DOSTORESTATE59 - SHA1_STORE_STATE(59) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(b, c, d, e, a, W, 59, temp); - -#ifdef DOSTORESTATE60 - SHA1_STORE_STATE(60) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, 60, temp); - -#ifdef DOSTORESTATE61 - SHA1_STORE_STATE(61) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(e, a, b, c, d, W, 61, temp); - -#ifdef DOSTORESTATE62 - SHA1_STORE_STATE(62) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(d, e, a, b, c, W, 62, temp); - -#ifdef DOSTORESTATE63 - SHA1_STORE_STATE(63) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(c, d, e, a, b, W, 63, temp); - -#ifdef DOSTORESTATE64 - SHA1_STORE_STATE(64) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(b, c, d, e, a, W, 64, temp); - -#ifdef DOSTORESTATE65 - SHA1_STORE_STATE(65) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, 65, temp); - -#ifdef DOSTORESTATE66 - SHA1_STORE_STATE(66) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(e, a, b, c, d, W, 66, temp); - -#ifdef DOSTORESTATE67 - SHA1_STORE_STATE(67) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(d, e, a, b, c, W, 67, temp); - -#ifdef DOSTORESTATE68 - SHA1_STORE_STATE(68) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(c, d, e, a, b, W, 68, temp); - -#ifdef DOSTORESTATE69 - SHA1_STORE_STATE(69) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(b, c, d, e, a, W, 69, temp); - -#ifdef DOSTORESTATE70 - SHA1_STORE_STATE(70) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, 70, temp); - -#ifdef DOSTORESTATE71 - SHA1_STORE_STATE(71) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(e, a, b, c, d, W, 71, temp); - -#ifdef DOSTORESTATE72 - SHA1_STORE_STATE(72) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(d, e, a, b, c, W, 72, temp); - -#ifdef DOSTORESTATE73 - SHA1_STORE_STATE(73) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(c, d, e, a, b, W, 73, temp); - -#ifdef DOSTORESTATE74 - SHA1_STORE_STATE(74) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(b, c, d, e, a, W, 74, temp); - -#ifdef DOSTORESTATE75 - SHA1_STORE_STATE(75) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, 75, temp); - -#ifdef DOSTORESTATE76 - SHA1_STORE_STATE(76) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(e, a, b, c, d, W, 76, temp); - -#ifdef DOSTORESTATE77 - SHA1_STORE_STATE(77) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(d, e, a, b, c, W, 77, temp); - -#ifdef DOSTORESTATE78 - SHA1_STORE_STATE(78) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(c, d, e, a, b, W, 78, temp); - -#ifdef DOSTORESTATE79 - SHA1_STORE_STATE(79) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(b, c, d, e, a, W, 79, temp); - - ihv[0] += a; - ihv[1] += b; - ihv[2] += c; - ihv[3] += d; - ihv[4] += e; -} - -#define SHA1_RECOMPRESS(t) \ - static void sha1recompress_fast_##t(uint32_t ihvin[5], uint32_t ihvout[5], const uint32_t me2[80], const uint32_t state[5]) \ - { \ - uint32_t a = state[0], b = state[1], c = state[2], d = state[3], e = state[4]; \ - if (t > 79) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(b, c, d, e, a, me2, 79); \ - if (t > 78) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(c, d, e, a, b, me2, 78); \ - if (t > 77) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(d, e, a, b, c, me2, 77); \ - if (t > 76) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(e, a, b, c, d, me2, 76); \ - if (t > 75) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, me2, 75); \ - if (t > 74) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(b, c, d, e, a, me2, 74); \ - if (t > 73) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(c, d, e, a, b, me2, 73); \ - if (t > 72) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(d, e, a, b, c, me2, 72); \ - if (t > 71) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(e, a, b, c, d, me2, 71); \ - if (t > 70) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, me2, 70); \ - if (t > 69) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(b, c, d, e, a, me2, 69); \ - if (t > 68) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(c, d, e, a, b, me2, 68); \ - if (t > 67) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(d, e, a, b, c, me2, 67); \ - if (t > 66) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(e, a, b, c, d, me2, 66); \ - if (t > 65) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, me2, 65); \ - if (t > 64) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(b, c, d, e, a, me2, 64); \ - if (t > 63) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(c, d, e, a, b, me2, 63); \ - if (t > 62) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(d, e, a, b, c, me2, 62); \ - if (t > 61) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(e, a, b, c, d, me2, 61); \ - if (t > 60) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, me2, 60); \ - if (t > 59) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(b, c, d, e, a, me2, 59); \ - if (t > 58) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(c, d, e, a, b, me2, 58); \ - if (t > 57) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(d, e, a, b, c, me2, 57); \ - if (t > 56) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(e, a, b, c, d, me2, 56); \ - if (t > 55) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, me2, 55); \ - if (t > 54) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(b, c, d, e, a, me2, 54); \ - if (t > 53) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(c, d, e, a, b, me2, 53); \ - if (t > 52) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(d, e, a, b, c, me2, 52); \ - if (t > 51) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(e, a, b, c, d, me2, 51); \ - if (t > 50) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, me2, 50); \ - if (t > 49) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(b, c, d, e, a, me2, 49); \ - if (t > 48) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(c, d, e, a, b, me2, 48); \ - if (t > 47) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(d, e, a, b, c, me2, 47); \ - if (t > 46) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(e, a, b, c, d, me2, 46); \ - if (t > 45) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, me2, 45); \ - if (t > 44) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(b, c, d, e, a, me2, 44); \ - if (t > 43) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(c, d, e, a, b, me2, 43); \ - if (t > 42) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(d, e, a, b, c, me2, 42); \ - if (t > 41) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(e, a, b, c, d, me2, 41); \ - if (t > 40) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, me2, 40); \ - if (t > 39) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(b, c, d, e, a, me2, 39); \ - if (t > 38) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(c, d, e, a, b, me2, 38); \ - if (t > 37) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(d, e, a, b, c, me2, 37); \ - if (t > 36) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(e, a, b, c, d, me2, 36); \ - if (t > 35) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, me2, 35); \ - if (t > 34) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(b, c, d, e, a, me2, 34); \ - if (t > 33) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(c, d, e, a, b, me2, 33); \ - if (t > 32) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(d, e, a, b, c, me2, 32); \ - if (t > 31) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(e, a, b, c, d, me2, 31); \ - if (t > 30) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, me2, 30); \ - if (t > 29) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(b, c, d, e, a, me2, 29); \ - if (t > 28) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(c, d, e, a, b, me2, 28); \ - if (t > 27) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(d, e, a, b, c, me2, 27); \ - if (t > 26) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(e, a, b, c, d, me2, 26); \ - if (t > 25) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, me2, 25); \ - if (t > 24) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(b, c, d, e, a, me2, 24); \ - if (t > 23) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(c, d, e, a, b, me2, 23); \ - if (t > 22) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(d, e, a, b, c, me2, 22); \ - if (t > 21) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(e, a, b, c, d, me2, 21); \ - if (t > 20) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, me2, 20); \ - if (t > 19) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(b, c, d, e, a, me2, 19); \ - if (t > 18) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(c, d, e, a, b, me2, 18); \ - if (t > 17) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(d, e, a, b, c, me2, 17); \ - if (t > 16) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(e, a, b, c, d, me2, 16); \ - if (t > 15) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, me2, 15); \ - if (t > 14) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(b, c, d, e, a, me2, 14); \ - if (t > 13) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(c, d, e, a, b, me2, 13); \ - if (t > 12) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(d, e, a, b, c, me2, 12); \ - if (t > 11) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(e, a, b, c, d, me2, 11); \ - if (t > 10) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, me2, 10); \ - if (t > 9) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(b, c, d, e, a, me2, 9); \ - if (t > 8) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(c, d, e, a, b, me2, 8); \ - if (t > 7) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(d, e, a, b, c, me2, 7); \ - if (t > 6) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(e, a, b, c, d, me2, 6); \ - if (t > 5) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, me2, 5); \ - if (t > 4) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(b, c, d, e, a, me2, 4); \ - if (t > 3) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(c, d, e, a, b, me2, 3); \ - if (t > 2) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(d, e, a, b, c, me2, 2); \ - if (t > 1) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(e, a, b, c, d, me2, 1); \ - if (t > 0) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, me2, 0); \ - ihvin[0] = a; \ - ihvin[1] = b; \ - ihvin[2] = c; \ - ihvin[3] = d; \ - ihvin[4] = e; \ - a = state[0]; \ - b = state[1]; \ - c = state[2]; \ - d = state[3]; \ - e = state[4]; \ - if (t <= 0) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, me2, 0); \ - if (t <= 1) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, me2, 1); \ - if (t <= 2) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, me2, 2); \ - if (t <= 3) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, me2, 3); \ - if (t <= 4) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, me2, 4); \ - if (t <= 5) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, me2, 5); \ - if (t <= 6) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, me2, 6); \ - if (t <= 7) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, me2, 7); \ - if (t <= 8) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, me2, 8); \ - if (t <= 9) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, me2, 9); \ - if (t <= 10) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, me2, 10); \ - if (t <= 11) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, me2, 11); \ - if (t <= 12) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, me2, 12); \ - if (t <= 13) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, me2, 13); \ - if (t <= 14) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, me2, 14); \ - if (t <= 15) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, me2, 15); \ - if (t <= 16) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, me2, 16); \ - if (t <= 17) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, me2, 17); \ - if (t <= 18) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, me2, 18); \ - if (t <= 19) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, me2, 19); \ - if (t <= 20) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, me2, 20); \ - if (t <= 21) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, me2, 21); \ - if (t <= 22) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, me2, 22); \ - if (t <= 23) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, me2, 23); \ - if (t <= 24) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, me2, 24); \ - if (t <= 25) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, me2, 25); \ - if (t <= 26) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, me2, 26); \ - if (t <= 27) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, me2, 27); \ - if (t <= 28) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, me2, 28); \ - if (t <= 29) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, me2, 29); \ - if (t <= 30) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, me2, 30); \ - if (t <= 31) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, me2, 31); \ - if (t <= 32) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, me2, 32); \ - if (t <= 33) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, me2, 33); \ - if (t <= 34) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, me2, 34); \ - if (t <= 35) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, me2, 35); \ - if (t <= 36) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, me2, 36); \ - if (t <= 37) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, me2, 37); \ - if (t <= 38) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, me2, 38); \ - if (t <= 39) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, me2, 39); \ - if (t <= 40) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, me2, 40); \ - if (t <= 41) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, me2, 41); \ - if (t <= 42) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, me2, 42); \ - if (t <= 43) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, me2, 43); \ - if (t <= 44) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, me2, 44); \ - if (t <= 45) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, me2, 45); \ - if (t <= 46) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, me2, 46); \ - if (t <= 47) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, me2, 47); \ - if (t <= 48) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, me2, 48); \ - if (t <= 49) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, me2, 49); \ - if (t <= 50) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, me2, 50); \ - if (t <= 51) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, me2, 51); \ - if (t <= 52) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, me2, 52); \ - if (t <= 53) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, me2, 53); \ - if (t <= 54) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, me2, 54); \ - if (t <= 55) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, me2, 55); \ - if (t <= 56) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, me2, 56); \ - if (t <= 57) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, me2, 57); \ - if (t <= 58) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, me2, 58); \ - if (t <= 59) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, me2, 59); \ - if (t <= 60) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, me2, 60); \ - if (t <= 61) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, me2, 61); \ - if (t <= 62) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, me2, 62); \ - if (t <= 63) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, me2, 63); \ - if (t <= 64) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, me2, 64); \ - if (t <= 65) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, me2, 65); \ - if (t <= 66) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, me2, 66); \ - if (t <= 67) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, me2, 67); \ - if (t <= 68) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, me2, 68); \ - if (t <= 69) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, me2, 69); \ - if (t <= 70) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, me2, 70); \ - if (t <= 71) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, me2, 71); \ - if (t <= 72) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, me2, 72); \ - if (t <= 73) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, me2, 73); \ - if (t <= 74) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, me2, 74); \ - if (t <= 75) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, me2, 75); \ - if (t <= 76) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, me2, 76); \ - if (t <= 77) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, me2, 77); \ - if (t <= 78) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, me2, 78); \ - if (t <= 79) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, me2, 79); \ - ihvout[0] = ihvin[0] + a; \ - ihvout[1] = ihvin[1] + b; \ - ihvout[2] = ihvin[2] + c; \ - ihvout[3] = ihvin[3] + d; \ - ihvout[4] = ihvin[4] + e; \ - } - -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4127) /* Compiler complains about the checks in the above macro being constant. */ -#endif - -#ifdef DOSTORESTATE0 -SHA1_RECOMPRESS(0) -#endif - -#ifdef DOSTORESTATE1 -SHA1_RECOMPRESS(1) -#endif - -#ifdef DOSTORESTATE2 -SHA1_RECOMPRESS(2) -#endif - -#ifdef DOSTORESTATE3 -SHA1_RECOMPRESS(3) -#endif - -#ifdef DOSTORESTATE4 -SHA1_RECOMPRESS(4) -#endif - -#ifdef DOSTORESTATE5 -SHA1_RECOMPRESS(5) -#endif - -#ifdef DOSTORESTATE6 -SHA1_RECOMPRESS(6) -#endif - -#ifdef DOSTORESTATE7 -SHA1_RECOMPRESS(7) -#endif - -#ifdef DOSTORESTATE8 -SHA1_RECOMPRESS(8) -#endif - -#ifdef DOSTORESTATE9 -SHA1_RECOMPRESS(9) -#endif - -#ifdef DOSTORESTATE10 -SHA1_RECOMPRESS(10) -#endif - -#ifdef DOSTORESTATE11 -SHA1_RECOMPRESS(11) -#endif - -#ifdef DOSTORESTATE12 -SHA1_RECOMPRESS(12) -#endif - -#ifdef DOSTORESTATE13 -SHA1_RECOMPRESS(13) -#endif - -#ifdef DOSTORESTATE14 -SHA1_RECOMPRESS(14) -#endif - -#ifdef DOSTORESTATE15 -SHA1_RECOMPRESS(15) -#endif - -#ifdef DOSTORESTATE16 -SHA1_RECOMPRESS(16) -#endif - -#ifdef DOSTORESTATE17 -SHA1_RECOMPRESS(17) -#endif - -#ifdef DOSTORESTATE18 -SHA1_RECOMPRESS(18) -#endif - -#ifdef DOSTORESTATE19 -SHA1_RECOMPRESS(19) -#endif - -#ifdef DOSTORESTATE20 -SHA1_RECOMPRESS(20) -#endif - -#ifdef DOSTORESTATE21 -SHA1_RECOMPRESS(21) -#endif - -#ifdef DOSTORESTATE22 -SHA1_RECOMPRESS(22) -#endif - -#ifdef DOSTORESTATE23 -SHA1_RECOMPRESS(23) -#endif - -#ifdef DOSTORESTATE24 -SHA1_RECOMPRESS(24) -#endif - -#ifdef DOSTORESTATE25 -SHA1_RECOMPRESS(25) -#endif - -#ifdef DOSTORESTATE26 -SHA1_RECOMPRESS(26) -#endif - -#ifdef DOSTORESTATE27 -SHA1_RECOMPRESS(27) -#endif - -#ifdef DOSTORESTATE28 -SHA1_RECOMPRESS(28) -#endif - -#ifdef DOSTORESTATE29 -SHA1_RECOMPRESS(29) -#endif - -#ifdef DOSTORESTATE30 -SHA1_RECOMPRESS(30) -#endif - -#ifdef DOSTORESTATE31 -SHA1_RECOMPRESS(31) -#endif - -#ifdef DOSTORESTATE32 -SHA1_RECOMPRESS(32) -#endif - -#ifdef DOSTORESTATE33 -SHA1_RECOMPRESS(33) -#endif - -#ifdef DOSTORESTATE34 -SHA1_RECOMPRESS(34) -#endif - -#ifdef DOSTORESTATE35 -SHA1_RECOMPRESS(35) -#endif - -#ifdef DOSTORESTATE36 -SHA1_RECOMPRESS(36) -#endif - -#ifdef DOSTORESTATE37 -SHA1_RECOMPRESS(37) -#endif - -#ifdef DOSTORESTATE38 -SHA1_RECOMPRESS(38) -#endif - -#ifdef DOSTORESTATE39 -SHA1_RECOMPRESS(39) -#endif - -#ifdef DOSTORESTATE40 -SHA1_RECOMPRESS(40) -#endif - -#ifdef DOSTORESTATE41 -SHA1_RECOMPRESS(41) -#endif - -#ifdef DOSTORESTATE42 -SHA1_RECOMPRESS(42) -#endif - -#ifdef DOSTORESTATE43 -SHA1_RECOMPRESS(43) -#endif - -#ifdef DOSTORESTATE44 -SHA1_RECOMPRESS(44) -#endif - -#ifdef DOSTORESTATE45 -SHA1_RECOMPRESS(45) -#endif - -#ifdef DOSTORESTATE46 -SHA1_RECOMPRESS(46) -#endif - -#ifdef DOSTORESTATE47 -SHA1_RECOMPRESS(47) -#endif - -#ifdef DOSTORESTATE48 -SHA1_RECOMPRESS(48) -#endif - -#ifdef DOSTORESTATE49 -SHA1_RECOMPRESS(49) -#endif - -#ifdef DOSTORESTATE50 -SHA1_RECOMPRESS(50) -#endif - -#ifdef DOSTORESTATE51 -SHA1_RECOMPRESS(51) -#endif - -#ifdef DOSTORESTATE52 -SHA1_RECOMPRESS(52) -#endif - -#ifdef DOSTORESTATE53 -SHA1_RECOMPRESS(53) -#endif - -#ifdef DOSTORESTATE54 -SHA1_RECOMPRESS(54) -#endif - -#ifdef DOSTORESTATE55 -SHA1_RECOMPRESS(55) -#endif - -#ifdef DOSTORESTATE56 -SHA1_RECOMPRESS(56) -#endif - -#ifdef DOSTORESTATE57 -SHA1_RECOMPRESS(57) -#endif - -#ifdef DOSTORESTATE58 -SHA1_RECOMPRESS(58) -#endif - -#ifdef DOSTORESTATE59 -SHA1_RECOMPRESS(59) -#endif - -#ifdef DOSTORESTATE60 -SHA1_RECOMPRESS(60) -#endif - -#ifdef DOSTORESTATE61 -SHA1_RECOMPRESS(61) -#endif - -#ifdef DOSTORESTATE62 -SHA1_RECOMPRESS(62) -#endif - -#ifdef DOSTORESTATE63 -SHA1_RECOMPRESS(63) -#endif - -#ifdef DOSTORESTATE64 -SHA1_RECOMPRESS(64) -#endif - -#ifdef DOSTORESTATE65 -SHA1_RECOMPRESS(65) -#endif - -#ifdef DOSTORESTATE66 -SHA1_RECOMPRESS(66) -#endif - -#ifdef DOSTORESTATE67 -SHA1_RECOMPRESS(67) -#endif - -#ifdef DOSTORESTATE68 -SHA1_RECOMPRESS(68) -#endif - -#ifdef DOSTORESTATE69 -SHA1_RECOMPRESS(69) -#endif - -#ifdef DOSTORESTATE70 -SHA1_RECOMPRESS(70) -#endif - -#ifdef DOSTORESTATE71 -SHA1_RECOMPRESS(71) -#endif - -#ifdef DOSTORESTATE72 -SHA1_RECOMPRESS(72) -#endif - -#ifdef DOSTORESTATE73 -SHA1_RECOMPRESS(73) -#endif - -#ifdef DOSTORESTATE74 -SHA1_RECOMPRESS(74) -#endif - -#ifdef DOSTORESTATE75 -SHA1_RECOMPRESS(75) -#endif - -#ifdef DOSTORESTATE76 -SHA1_RECOMPRESS(76) -#endif - -#ifdef DOSTORESTATE77 -SHA1_RECOMPRESS(77) -#endif - -#ifdef DOSTORESTATE78 -SHA1_RECOMPRESS(78) -#endif - -#ifdef DOSTORESTATE79 -SHA1_RECOMPRESS(79) -#endif - -#ifdef _MSC_VER -#pragma warning(pop) -#endif - -static void sha1_recompression_step(uint32_t step, uint32_t ihvin[5], uint32_t ihvout[5], const uint32_t me2[80], const uint32_t state[5]) -{ - switch (step) - { -#ifdef DOSTORESTATE0 - case 0: - sha1recompress_fast_0(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE1 - case 1: - sha1recompress_fast_1(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE2 - case 2: - sha1recompress_fast_2(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE3 - case 3: - sha1recompress_fast_3(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE4 - case 4: - sha1recompress_fast_4(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE5 - case 5: - sha1recompress_fast_5(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE6 - case 6: - sha1recompress_fast_6(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE7 - case 7: - sha1recompress_fast_7(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE8 - case 8: - sha1recompress_fast_8(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE9 - case 9: - sha1recompress_fast_9(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE10 - case 10: - sha1recompress_fast_10(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE11 - case 11: - sha1recompress_fast_11(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE12 - case 12: - sha1recompress_fast_12(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE13 - case 13: - sha1recompress_fast_13(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE14 - case 14: - sha1recompress_fast_14(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE15 - case 15: - sha1recompress_fast_15(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE16 - case 16: - sha1recompress_fast_16(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE17 - case 17: - sha1recompress_fast_17(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE18 - case 18: - sha1recompress_fast_18(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE19 - case 19: - sha1recompress_fast_19(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE20 - case 20: - sha1recompress_fast_20(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE21 - case 21: - sha1recompress_fast_21(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE22 - case 22: - sha1recompress_fast_22(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE23 - case 23: - sha1recompress_fast_23(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE24 - case 24: - sha1recompress_fast_24(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE25 - case 25: - sha1recompress_fast_25(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE26 - case 26: - sha1recompress_fast_26(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE27 - case 27: - sha1recompress_fast_27(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE28 - case 28: - sha1recompress_fast_28(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE29 - case 29: - sha1recompress_fast_29(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE30 - case 30: - sha1recompress_fast_30(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE31 - case 31: - sha1recompress_fast_31(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE32 - case 32: - sha1recompress_fast_32(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE33 - case 33: - sha1recompress_fast_33(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE34 - case 34: - sha1recompress_fast_34(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE35 - case 35: - sha1recompress_fast_35(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE36 - case 36: - sha1recompress_fast_36(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE37 - case 37: - sha1recompress_fast_37(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE38 - case 38: - sha1recompress_fast_38(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE39 - case 39: - sha1recompress_fast_39(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE40 - case 40: - sha1recompress_fast_40(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE41 - case 41: - sha1recompress_fast_41(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE42 - case 42: - sha1recompress_fast_42(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE43 - case 43: - sha1recompress_fast_43(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE44 - case 44: - sha1recompress_fast_44(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE45 - case 45: - sha1recompress_fast_45(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE46 - case 46: - sha1recompress_fast_46(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE47 - case 47: - sha1recompress_fast_47(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE48 - case 48: - sha1recompress_fast_48(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE49 - case 49: - sha1recompress_fast_49(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE50 - case 50: - sha1recompress_fast_50(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE51 - case 51: - sha1recompress_fast_51(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE52 - case 52: - sha1recompress_fast_52(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE53 - case 53: - sha1recompress_fast_53(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE54 - case 54: - sha1recompress_fast_54(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE55 - case 55: - sha1recompress_fast_55(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE56 - case 56: - sha1recompress_fast_56(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE57 - case 57: - sha1recompress_fast_57(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE58 - case 58: - sha1recompress_fast_58(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE59 - case 59: - sha1recompress_fast_59(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE60 - case 60: - sha1recompress_fast_60(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE61 - case 61: - sha1recompress_fast_61(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE62 - case 62: - sha1recompress_fast_62(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE63 - case 63: - sha1recompress_fast_63(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE64 - case 64: - sha1recompress_fast_64(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE65 - case 65: - sha1recompress_fast_65(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE66 - case 66: - sha1recompress_fast_66(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE67 - case 67: - sha1recompress_fast_67(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE68 - case 68: - sha1recompress_fast_68(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE69 - case 69: - sha1recompress_fast_69(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE70 - case 70: - sha1recompress_fast_70(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE71 - case 71: - sha1recompress_fast_71(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE72 - case 72: - sha1recompress_fast_72(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE73 - case 73: - sha1recompress_fast_73(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE74 - case 74: - sha1recompress_fast_74(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE75 - case 75: - sha1recompress_fast_75(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE76 - case 76: - sha1recompress_fast_76(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE77 - case 77: - sha1recompress_fast_77(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE78 - case 78: - sha1recompress_fast_78(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE79 - case 79: - sha1recompress_fast_79(ihvin, ihvout, me2, state); - break; -#endif - default: - abort(); - } -} - -static void sha1_process(SHA1_CTX *ctx, const uint32_t block[16]) -{ - unsigned i, j; - uint32_t ubc_dv_mask[DVMASKSIZE] = {0xFFFFFFFF}; - uint32_t ihvtmp[5]; - - ctx->ihv1[0] = ctx->ihv[0]; - ctx->ihv1[1] = ctx->ihv[1]; - ctx->ihv1[2] = ctx->ihv[2]; - ctx->ihv1[3] = ctx->ihv[3]; - ctx->ihv1[4] = ctx->ihv[4]; - - sha1_compression_states(ctx->ihv, block, ctx->m1, ctx->states); - - if (ctx->detect_coll) - { - if (ctx->ubc_check) - { - ubc_check(ctx->m1, ubc_dv_mask); - } - - if (ubc_dv_mask[0] != 0) - { - for (i = 0; sha1_dvs[i].dvType != 0; ++i) - { - if (ubc_dv_mask[0] & ((uint32_t)(1) << sha1_dvs[i].maskb)) - { - for (j = 0; j < 80; ++j) - ctx->m2[j] = ctx->m1[j] ^ sha1_dvs[i].dm[j]; - - sha1_recompression_step(sha1_dvs[i].testt, ctx->ihv2, ihvtmp, ctx->m2, ctx->states[sha1_dvs[i].testt]); - - /* to verify SHA-1 collision detection code with collisions for reduced-step SHA-1 */ - if ((0 == ((ihvtmp[0] ^ ctx->ihv[0]) | (ihvtmp[1] ^ ctx->ihv[1]) | (ihvtmp[2] ^ ctx->ihv[2]) | (ihvtmp[3] ^ ctx->ihv[3]) | (ihvtmp[4] ^ ctx->ihv[4]))) || - (ctx->reduced_round_coll && 0 == ((ctx->ihv1[0] ^ ctx->ihv2[0]) | (ctx->ihv1[1] ^ ctx->ihv2[1]) | (ctx->ihv1[2] ^ ctx->ihv2[2]) | (ctx->ihv1[3] ^ ctx->ihv2[3]) | (ctx->ihv1[4] ^ ctx->ihv2[4])))) - { - ctx->found_collision = 1; - - if (ctx->safe_hash) - { - sha1_compression_W(ctx->ihv, ctx->m1); - sha1_compression_W(ctx->ihv, ctx->m1); - } - - break; - } - } - } - } - } -} - -void SHA1DCInit(SHA1_CTX *ctx) -{ - ctx->total = 0; - ctx->ihv[0] = 0x67452301; - ctx->ihv[1] = 0xEFCDAB89; - ctx->ihv[2] = 0x98BADCFE; - ctx->ihv[3] = 0x10325476; - ctx->ihv[4] = 0xC3D2E1F0; - ctx->found_collision = 0; - ctx->safe_hash = SHA1DC_INIT_SAFE_HASH_DEFAULT; - ctx->ubc_check = 1; - ctx->detect_coll = 1; - ctx->reduced_round_coll = 0; - ctx->callback = NULL; -} - -void SHA1DCSetSafeHash(SHA1_CTX *ctx, int safehash) -{ - if (safehash) - ctx->safe_hash = 1; - else - ctx->safe_hash = 0; -} - -void SHA1DCSetUseUBC(SHA1_CTX *ctx, int ubc_check) -{ - if (ubc_check) - ctx->ubc_check = 1; - else - ctx->ubc_check = 0; -} - -void SHA1DCSetUseDetectColl(SHA1_CTX *ctx, int detect_coll) -{ - if (detect_coll) - ctx->detect_coll = 1; - else - ctx->detect_coll = 0; -} - -void SHA1DCSetDetectReducedRoundCollision(SHA1_CTX *ctx, int reduced_round_coll) -{ - if (reduced_round_coll) - ctx->reduced_round_coll = 1; - else - ctx->reduced_round_coll = 0; -} - -void SHA1DCSetCallback(SHA1_CTX *ctx, collision_block_callback callback) -{ - ctx->callback = callback; -} - -void SHA1DCUpdate(SHA1_CTX *ctx, const char *buf, size_t len) -{ - unsigned left, fill; - - if (len == 0) - return; - - left = ctx->total & 63; - fill = 64 - left; - - if (left && len >= fill) - { - ctx->total += fill; - memcpy(ctx->buffer + left, buf, fill); - sha1_process(ctx, (uint32_t *)(ctx->buffer)); - buf += fill; - len -= fill; - left = 0; - } - while (len >= 64) - { - ctx->total += 64; - -#if defined(SHA1DC_ALLOW_UNALIGNED_ACCESS) - sha1_process(ctx, (uint32_t *)(buf)); -#else - memcpy(ctx->buffer, buf, 64); - sha1_process(ctx, (uint32_t *)(ctx->buffer)); -#endif /* defined(SHA1DC_ALLOW_UNALIGNED_ACCESS) */ - buf += 64; - len -= 64; - } - if (len > 0) - { - ctx->total += len; - memcpy(ctx->buffer + left, buf, len); - } -} - -static const unsigned char sha1_padding[64] = - { - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - -int SHA1DCFinal(unsigned char output[20], SHA1_CTX *ctx) -{ - uint32_t last = ctx->total & 63; - uint32_t padn = (last < 56) ? (56 - last) : (120 - last); - uint64_t total; - SHA1DCUpdate(ctx, (const char *)(sha1_padding), padn); - - total = ctx->total - padn; - total <<= 3; - ctx->buffer[56] = (unsigned char)(total >> 56); - ctx->buffer[57] = (unsigned char)(total >> 48); - ctx->buffer[58] = (unsigned char)(total >> 40); - ctx->buffer[59] = (unsigned char)(total >> 32); - ctx->buffer[60] = (unsigned char)(total >> 24); - ctx->buffer[61] = (unsigned char)(total >> 16); - ctx->buffer[62] = (unsigned char)(total >> 8); - ctx->buffer[63] = (unsigned char)(total); - sha1_process(ctx, (uint32_t *)(ctx->buffer)); - output[0] = (unsigned char)(ctx->ihv[0] >> 24); - output[1] = (unsigned char)(ctx->ihv[0] >> 16); - output[2] = (unsigned char)(ctx->ihv[0] >> 8); - output[3] = (unsigned char)(ctx->ihv[0]); - output[4] = (unsigned char)(ctx->ihv[1] >> 24); - output[5] = (unsigned char)(ctx->ihv[1] >> 16); - output[6] = (unsigned char)(ctx->ihv[1] >> 8); - output[7] = (unsigned char)(ctx->ihv[1]); - output[8] = (unsigned char)(ctx->ihv[2] >> 24); - output[9] = (unsigned char)(ctx->ihv[2] >> 16); - output[10] = (unsigned char)(ctx->ihv[2] >> 8); - output[11] = (unsigned char)(ctx->ihv[2]); - output[12] = (unsigned char)(ctx->ihv[3] >> 24); - output[13] = (unsigned char)(ctx->ihv[3] >> 16); - output[14] = (unsigned char)(ctx->ihv[3] >> 8); - output[15] = (unsigned char)(ctx->ihv[3]); - output[16] = (unsigned char)(ctx->ihv[4] >> 24); - output[17] = (unsigned char)(ctx->ihv[4] >> 16); - output[18] = (unsigned char)(ctx->ihv[4] >> 8); - output[19] = (unsigned char)(ctx->ihv[4]); - return ctx->found_collision; -} - -#ifdef SHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_C -#include SHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_C -#endif diff --git a/vendor/github.com/pjbgf/sha1cd/cgo/sha1.h b/vendor/github.com/pjbgf/sha1cd/cgo/sha1.h deleted file mode 100644 index ce4942f617..0000000000 --- a/vendor/github.com/pjbgf/sha1cd/cgo/sha1.h +++ /dev/null @@ -1,114 +0,0 @@ -/*** - * Copyright 2017 Marc Stevens , Dan Shumow - * Distributed under the MIT Software License. - * See accompanying file LICENSE.txt or copy at - * https://opensource.org/licenses/MIT - ***/ - -// Originally from: https://github.com/cr-marcstevens/sha1collisiondetection - -#ifndef SHA1DC_SHA1_H -#define SHA1DC_SHA1_H - -#if defined(__cplusplus) -extern "C" -{ -#endif - -#ifndef SHA1DC_NO_STANDARD_INCLUDES -#include -#endif - - /* sha-1 compression function that takes an already expanded message, and additionally store intermediate states */ - /* only stores states ii (the state between step ii-1 and step ii) when DOSTORESTATEii is defined in ubc_check.h */ - void sha1_compression_states(uint32_t[5], const uint32_t[16], uint32_t[80], uint32_t[80][5]); - - /* - // Function type for sha1_recompression_step_T (uint32_t ihvin[5], uint32_t ihvout[5], const uint32_t me2[80], const uint32_t state[5]). - // Where 0 <= T < 80 - // me2 is an expanded message (the expansion of an original message block XOR'ed with a disturbance vector's message block difference.) - // state is the internal state (a,b,c,d,e) before step T of the SHA-1 compression function while processing the original message block. - // The function will return: - // ihvin: The reconstructed input chaining value. - // ihvout: The reconstructed output chaining value. - */ - typedef void (*sha1_recompression_type)(uint32_t *, uint32_t *, const uint32_t *, const uint32_t *); - - /* A callback function type that can be set to be called when a collision block has been found: */ - /* void collision_block_callback(uint64_t byteoffset, const uint32_t ihvin1[5], const uint32_t ihvin2[5], const uint32_t m1[80], const uint32_t m2[80]) */ - typedef void (*collision_block_callback)(uint64_t, const uint32_t *, const uint32_t *, const uint32_t *, const uint32_t *); - - /* The SHA-1 context. */ - typedef struct - { - uint64_t total; - uint32_t ihv[5]; - unsigned char buffer[64]; - int found_collision; - int safe_hash; - int detect_coll; - int ubc_check; - int reduced_round_coll; - collision_block_callback callback; - - uint32_t ihv1[5]; - uint32_t ihv2[5]; - uint32_t m1[80]; - uint32_t m2[80]; - uint32_t states[80][5]; - } SHA1_CTX; - - /* Initialize SHA-1 context. */ - void SHA1DCInit(SHA1_CTX *); - - /* - Function to enable safe SHA-1 hashing: - Collision attacks are thwarted by hashing a detected near-collision block 3 times. - Think of it as extending SHA-1 from 80-steps to 240-steps for such blocks: - The best collision attacks against SHA-1 have complexity about 2^60, - thus for 240-steps an immediate lower-bound for the best cryptanalytic attacks would be 2^180. - An attacker would be better off using a generic birthday search of complexity 2^80. - - Enabling safe SHA-1 hashing will result in the correct SHA-1 hash for messages where no collision attack was detected, - but it will result in a different SHA-1 hash for messages where a collision attack was detected. - This will automatically invalidate SHA-1 based digital signature forgeries. - Enabled by default. - */ - void SHA1DCSetSafeHash(SHA1_CTX *, int); - - /* - Function to disable or enable the use of Unavoidable Bitconditions (provides a significant speed up). - Enabled by default - */ - void SHA1DCSetUseUBC(SHA1_CTX *, int); - - /* - Function to disable or enable the use of Collision Detection. - Enabled by default. - */ - void SHA1DCSetUseDetectColl(SHA1_CTX *, int); - - /* function to disable or enable the detection of reduced-round SHA-1 collisions */ - /* disabled by default */ - void SHA1DCSetDetectReducedRoundCollision(SHA1_CTX *, int); - - /* function to set a callback function, pass NULL to disable */ - /* by default no callback set */ - void SHA1DCSetCallback(SHA1_CTX *, collision_block_callback); - - /* update SHA-1 context with buffer contents */ - void SHA1DCUpdate(SHA1_CTX *, const char *, size_t); - - /* obtain SHA-1 hash from SHA-1 context */ - /* returns: 0 = no collision detected, otherwise = collision found => warn user for active attack */ - int SHA1DCFinal(unsigned char[20], SHA1_CTX *); - -#if defined(__cplusplus) -} -#endif - -#ifdef SHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_H -#include SHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_H -#endif - -#endif diff --git a/vendor/github.com/pjbgf/sha1cd/cgo/ubc_check.c b/vendor/github.com/pjbgf/sha1cd/cgo/ubc_check.c deleted file mode 100644 index b3d58ce282..0000000000 --- a/vendor/github.com/pjbgf/sha1cd/cgo/ubc_check.c +++ /dev/null @@ -1,297 +0,0 @@ -/*** - * Copyright 2017 Marc Stevens , Dan Shumow - * Distributed under the MIT Software License. - * See accompanying file LICENSE.txt or copy at - * https://opensource.org/licenses/MIT - ***/ - -// Originally from: https://github.com/cr-marcstevens/sha1collisiondetection - -/* -// this file was generated by the 'parse_bitrel' program in the tools section -// using the data files from directory 'tools/data/3565' -// -// sha1_dvs contains a list of SHA-1 Disturbance Vectors (DV) to check -// dvType, dvK and dvB define the DV: I(K,B) or II(K,B) (see the paper) -// dm[80] is the expanded message block XOR-difference defined by the DV -// testt is the step to do the recompression from for collision detection -// maski and maskb define the bit to check for each DV in the dvmask returned by ubc_check -// -// ubc_check takes as input an expanded message block and verifies the unavoidable bitconditions for all listed DVs -// it returns a dvmask where each bit belonging to a DV is set if all unavoidable bitconditions for that DV have been met -// thus one needs to do the recompression check for each DV that has its bit set -// -// ubc_check is programmatically generated and the unavoidable bitconditions have been hardcoded -// a directly verifiable version named ubc_check_verify can be found in ubc_check_verify.c -// ubc_check has been verified against ubc_check_verify using the 'ubc_check_test' program in the tools section -*/ - -#ifndef SHA1DC_NO_STANDARD_INCLUDES -#include -#endif -#ifdef SHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C -#include SHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C -#endif -#include "ubc_check.h" - -static const uint32_t DV_I_43_0_bit = (uint32_t)(1) << 0; -static const uint32_t DV_I_44_0_bit = (uint32_t)(1) << 1; -static const uint32_t DV_I_45_0_bit = (uint32_t)(1) << 2; -static const uint32_t DV_I_46_0_bit = (uint32_t)(1) << 3; -static const uint32_t DV_I_46_2_bit = (uint32_t)(1) << 4; -static const uint32_t DV_I_47_0_bit = (uint32_t)(1) << 5; -static const uint32_t DV_I_47_2_bit = (uint32_t)(1) << 6; -static const uint32_t DV_I_48_0_bit = (uint32_t)(1) << 7; -static const uint32_t DV_I_48_2_bit = (uint32_t)(1) << 8; -static const uint32_t DV_I_49_0_bit = (uint32_t)(1) << 9; -static const uint32_t DV_I_49_2_bit = (uint32_t)(1) << 10; -static const uint32_t DV_I_50_0_bit = (uint32_t)(1) << 11; -static const uint32_t DV_I_50_2_bit = (uint32_t)(1) << 12; -static const uint32_t DV_I_51_0_bit = (uint32_t)(1) << 13; -static const uint32_t DV_I_51_2_bit = (uint32_t)(1) << 14; -static const uint32_t DV_I_52_0_bit = (uint32_t)(1) << 15; -static const uint32_t DV_II_45_0_bit = (uint32_t)(1) << 16; -static const uint32_t DV_II_46_0_bit = (uint32_t)(1) << 17; -static const uint32_t DV_II_46_2_bit = (uint32_t)(1) << 18; -static const uint32_t DV_II_47_0_bit = (uint32_t)(1) << 19; -static const uint32_t DV_II_48_0_bit = (uint32_t)(1) << 20; -static const uint32_t DV_II_49_0_bit = (uint32_t)(1) << 21; -static const uint32_t DV_II_49_2_bit = (uint32_t)(1) << 22; -static const uint32_t DV_II_50_0_bit = (uint32_t)(1) << 23; -static const uint32_t DV_II_50_2_bit = (uint32_t)(1) << 24; -static const uint32_t DV_II_51_0_bit = (uint32_t)(1) << 25; -static const uint32_t DV_II_51_2_bit = (uint32_t)(1) << 26; -static const uint32_t DV_II_52_0_bit = (uint32_t)(1) << 27; -static const uint32_t DV_II_53_0_bit = (uint32_t)(1) << 28; -static const uint32_t DV_II_54_0_bit = (uint32_t)(1) << 29; -static const uint32_t DV_II_55_0_bit = (uint32_t)(1) << 30; -static const uint32_t DV_II_56_0_bit = (uint32_t)(1) << 31; - -dv_info_t sha1_dvs[] = - { - {1, 43, 0, 58, 0, 0, {0x08000000, 0x9800000c, 0xd8000010, 0x08000010, 0xb8000010, 0x98000000, 0x60000000, 0x00000008, 0xc0000000, 0x90000014, 0x10000010, 0xb8000014, 0x28000000, 0x20000010, 0x48000000, 0x08000018, 0x60000000, 0x90000010, 0xf0000010, 0x90000008, 0xc0000000, 0x90000010, 0xf0000010, 0xb0000008, 0x40000000, 0x90000000, 0xf0000010, 0x90000018, 0x60000000, 0x90000010, 0x90000010, 0x90000000, 0x80000000, 0x00000010, 0xa0000000, 0x20000000, 0xa0000000, 0x20000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x20000000, 0x00000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000040, 0x40000002, 0x80000004, 0x80000080, 0x80000006, 0x00000049, 0x00000103, 0x80000009, 0x80000012, 0x80000202, 0x00000018, 0x00000164, 0x00000408, 0x800000e6, 0x8000004c, 0x00000803, 0x80000161, 0x80000599}}, {1, 44, 0, 58, 0, 1, {0xb4000008, 0x08000000, 0x9800000c, 0xd8000010, 0x08000010, 0xb8000010, 0x98000000, 0x60000000, 0x00000008, 0xc0000000, 0x90000014, 0x10000010, 0xb8000014, 0x28000000, 0x20000010, 0x48000000, 0x08000018, 0x60000000, 0x90000010, 0xf0000010, 0x90000008, 0xc0000000, 0x90000010, 0xf0000010, 0xb0000008, 0x40000000, 0x90000000, 0xf0000010, 0x90000018, 0x60000000, 0x90000010, 0x90000010, 0x90000000, 0x80000000, 0x00000010, 0xa0000000, 0x20000000, 0xa0000000, 0x20000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x20000000, 0x00000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000040, 0x40000002, 0x80000004, 0x80000080, 0x80000006, 0x00000049, 0x00000103, 0x80000009, 0x80000012, 0x80000202, 0x00000018, 0x00000164, 0x00000408, 0x800000e6, 0x8000004c, 0x00000803, 0x80000161}}, {1, 45, 0, 58, 0, 2, {0xf4000014, 0xb4000008, 0x08000000, 0x9800000c, 0xd8000010, 0x08000010, 0xb8000010, 0x98000000, 0x60000000, 0x00000008, 0xc0000000, 0x90000014, 0x10000010, 0xb8000014, 0x28000000, 0x20000010, 0x48000000, 0x08000018, 0x60000000, 0x90000010, 0xf0000010, 0x90000008, 0xc0000000, 0x90000010, 0xf0000010, 0xb0000008, 0x40000000, 0x90000000, 0xf0000010, 0x90000018, 0x60000000, 0x90000010, 0x90000010, 0x90000000, 0x80000000, 0x00000010, 0xa0000000, 0x20000000, 0xa0000000, 0x20000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x20000000, 0x00000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000040, 0x40000002, 0x80000004, 0x80000080, 0x80000006, 0x00000049, 0x00000103, 0x80000009, 0x80000012, 0x80000202, 0x00000018, 0x00000164, 0x00000408, 0x800000e6, 0x8000004c, 0x00000803}}, {1, 46, 0, 58, 0, 3, {0x2c000010, 0xf4000014, 0xb4000008, 0x08000000, 0x9800000c, 0xd8000010, 0x08000010, 0xb8000010, 0x98000000, 0x60000000, 0x00000008, 0xc0000000, 0x90000014, 0x10000010, 0xb8000014, 0x28000000, 0x20000010, 0x48000000, 0x08000018, 0x60000000, 0x90000010, 0xf0000010, 0x90000008, 0xc0000000, 0x90000010, 0xf0000010, 0xb0000008, 0x40000000, 0x90000000, 0xf0000010, 0x90000018, 0x60000000, 0x90000010, 0x90000010, 0x90000000, 0x80000000, 0x00000010, 0xa0000000, 0x20000000, 0xa0000000, 0x20000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x20000000, 0x00000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000040, 0x40000002, 0x80000004, 0x80000080, 0x80000006, 0x00000049, 0x00000103, 0x80000009, 0x80000012, 0x80000202, 0x00000018, 0x00000164, 0x00000408, 0x800000e6, 0x8000004c}}, {1, 46, 2, 58, 0, 4, {0xb0000040, 0xd0000053, 0xd0000022, 0x20000000, 0x60000032, 0x60000043, 0x20000040, 0xe0000042, 0x60000002, 0x80000001, 0x00000020, 0x00000003, 0x40000052, 0x40000040, 0xe0000052, 0xa0000000, 0x80000040, 0x20000001, 0x20000060, 0x80000001, 0x40000042, 0xc0000043, 0x40000022, 0x00000003, 0x40000042, 0xc0000043, 0xc0000022, 0x00000001, 0x40000002, 0xc0000043, 0x40000062, 0x80000001, 0x40000042, 0x40000042, 0x40000002, 0x00000002, 0x00000040, 0x80000002, 0x80000000, 0x80000002, 0x80000040, 0x00000000, 0x80000040, 0x80000000, 0x00000040, 0x80000000, 0x00000040, 0x80000002, 0x00000000, 0x80000000, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000080, 0x00000004, 0x00000009, 0x00000101, 0x00000009, 0x00000012, 0x00000202, 0x0000001a, 0x00000124, 0x0000040c, 0x00000026, 0x0000004a, 0x0000080a, 0x00000060, 0x00000590, 0x00001020, 0x0000039a, 0x00000132}}, {1, 47, 0, 58, 0, 5, {0xc8000010, 0x2c000010, 0xf4000014, 0xb4000008, 0x08000000, 0x9800000c, 0xd8000010, 0x08000010, 0xb8000010, 0x98000000, 0x60000000, 0x00000008, 0xc0000000, 0x90000014, 0x10000010, 0xb8000014, 0x28000000, 0x20000010, 0x48000000, 0x08000018, 0x60000000, 0x90000010, 0xf0000010, 0x90000008, 0xc0000000, 0x90000010, 0xf0000010, 0xb0000008, 0x40000000, 0x90000000, 0xf0000010, 0x90000018, 0x60000000, 0x90000010, 0x90000010, 0x90000000, 0x80000000, 0x00000010, 0xa0000000, 0x20000000, 0xa0000000, 0x20000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x20000000, 0x00000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000040, 0x40000002, 0x80000004, 0x80000080, 0x80000006, 0x00000049, 0x00000103, 0x80000009, 0x80000012, 0x80000202, 0x00000018, 0x00000164, 0x00000408, 0x800000e6}}, {1, 47, 2, 58, 0, 6, {0x20000043, 0xb0000040, 0xd0000053, 0xd0000022, 0x20000000, 0x60000032, 0x60000043, 0x20000040, 0xe0000042, 0x60000002, 0x80000001, 0x00000020, 0x00000003, 0x40000052, 0x40000040, 0xe0000052, 0xa0000000, 0x80000040, 0x20000001, 0x20000060, 0x80000001, 0x40000042, 0xc0000043, 0x40000022, 0x00000003, 0x40000042, 0xc0000043, 0xc0000022, 0x00000001, 0x40000002, 0xc0000043, 0x40000062, 0x80000001, 0x40000042, 0x40000042, 0x40000002, 0x00000002, 0x00000040, 0x80000002, 0x80000000, 0x80000002, 0x80000040, 0x00000000, 0x80000040, 0x80000000, 0x00000040, 0x80000000, 0x00000040, 0x80000002, 0x00000000, 0x80000000, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000080, 0x00000004, 0x00000009, 0x00000101, 0x00000009, 0x00000012, 0x00000202, 0x0000001a, 0x00000124, 0x0000040c, 0x00000026, 0x0000004a, 0x0000080a, 0x00000060, 0x00000590, 0x00001020, 0x0000039a}}, {1, 48, 0, 58, 0, 7, {0xb800000a, 0xc8000010, 0x2c000010, 0xf4000014, 0xb4000008, 0x08000000, 0x9800000c, 0xd8000010, 0x08000010, 0xb8000010, 0x98000000, 0x60000000, 0x00000008, 0xc0000000, 0x90000014, 0x10000010, 0xb8000014, 0x28000000, 0x20000010, 0x48000000, 0x08000018, 0x60000000, 0x90000010, 0xf0000010, 0x90000008, 0xc0000000, 0x90000010, 0xf0000010, 0xb0000008, 0x40000000, 0x90000000, 0xf0000010, 0x90000018, 0x60000000, 0x90000010, 0x90000010, 0x90000000, 0x80000000, 0x00000010, 0xa0000000, 0x20000000, 0xa0000000, 0x20000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x20000000, 0x00000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000040, 0x40000002, 0x80000004, 0x80000080, 0x80000006, 0x00000049, 0x00000103, 0x80000009, 0x80000012, 0x80000202, 0x00000018, 0x00000164, 0x00000408}}, {1, 48, 2, 58, 0, 8, {0xe000002a, 0x20000043, 0xb0000040, 0xd0000053, 0xd0000022, 0x20000000, 0x60000032, 0x60000043, 0x20000040, 0xe0000042, 0x60000002, 0x80000001, 0x00000020, 0x00000003, 0x40000052, 0x40000040, 0xe0000052, 0xa0000000, 0x80000040, 0x20000001, 0x20000060, 0x80000001, 0x40000042, 0xc0000043, 0x40000022, 0x00000003, 0x40000042, 0xc0000043, 0xc0000022, 0x00000001, 0x40000002, 0xc0000043, 0x40000062, 0x80000001, 0x40000042, 0x40000042, 0x40000002, 0x00000002, 0x00000040, 0x80000002, 0x80000000, 0x80000002, 0x80000040, 0x00000000, 0x80000040, 0x80000000, 0x00000040, 0x80000000, 0x00000040, 0x80000002, 0x00000000, 0x80000000, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000080, 0x00000004, 0x00000009, 0x00000101, 0x00000009, 0x00000012, 0x00000202, 0x0000001a, 0x00000124, 0x0000040c, 0x00000026, 0x0000004a, 0x0000080a, 0x00000060, 0x00000590, 0x00001020}}, {1, 49, 0, 58, 0, 9, {0x18000000, 0xb800000a, 0xc8000010, 0x2c000010, 0xf4000014, 0xb4000008, 0x08000000, 0x9800000c, 0xd8000010, 0x08000010, 0xb8000010, 0x98000000, 0x60000000, 0x00000008, 0xc0000000, 0x90000014, 0x10000010, 0xb8000014, 0x28000000, 0x20000010, 0x48000000, 0x08000018, 0x60000000, 0x90000010, 0xf0000010, 0x90000008, 0xc0000000, 0x90000010, 0xf0000010, 0xb0000008, 0x40000000, 0x90000000, 0xf0000010, 0x90000018, 0x60000000, 0x90000010, 0x90000010, 0x90000000, 0x80000000, 0x00000010, 0xa0000000, 0x20000000, 0xa0000000, 0x20000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x20000000, 0x00000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000040, 0x40000002, 0x80000004, 0x80000080, 0x80000006, 0x00000049, 0x00000103, 0x80000009, 0x80000012, 0x80000202, 0x00000018, 0x00000164}}, {1, 49, 2, 58, 0, 10, {0x60000000, 0xe000002a, 0x20000043, 0xb0000040, 0xd0000053, 0xd0000022, 0x20000000, 0x60000032, 0x60000043, 0x20000040, 0xe0000042, 0x60000002, 0x80000001, 0x00000020, 0x00000003, 0x40000052, 0x40000040, 0xe0000052, 0xa0000000, 0x80000040, 0x20000001, 0x20000060, 0x80000001, 0x40000042, 0xc0000043, 0x40000022, 0x00000003, 0x40000042, 0xc0000043, 0xc0000022, 0x00000001, 0x40000002, 0xc0000043, 0x40000062, 0x80000001, 0x40000042, 0x40000042, 0x40000002, 0x00000002, 0x00000040, 0x80000002, 0x80000000, 0x80000002, 0x80000040, 0x00000000, 0x80000040, 0x80000000, 0x00000040, 0x80000000, 0x00000040, 0x80000002, 0x00000000, 0x80000000, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000080, 0x00000004, 0x00000009, 0x00000101, 0x00000009, 0x00000012, 0x00000202, 0x0000001a, 0x00000124, 0x0000040c, 0x00000026, 0x0000004a, 0x0000080a, 0x00000060, 0x00000590}}, {1, 50, 0, 65, 0, 11, {0x0800000c, 0x18000000, 0xb800000a, 0xc8000010, 0x2c000010, 0xf4000014, 0xb4000008, 0x08000000, 0x9800000c, 0xd8000010, 0x08000010, 0xb8000010, 0x98000000, 0x60000000, 0x00000008, 0xc0000000, 0x90000014, 0x10000010, 0xb8000014, 0x28000000, 0x20000010, 0x48000000, 0x08000018, 0x60000000, 0x90000010, 0xf0000010, 0x90000008, 0xc0000000, 0x90000010, 0xf0000010, 0xb0000008, 0x40000000, 0x90000000, 0xf0000010, 0x90000018, 0x60000000, 0x90000010, 0x90000010, 0x90000000, 0x80000000, 0x00000010, 0xa0000000, 0x20000000, 0xa0000000, 0x20000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x20000000, 0x00000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000040, 0x40000002, 0x80000004, 0x80000080, 0x80000006, 0x00000049, 0x00000103, 0x80000009, 0x80000012, 0x80000202, 0x00000018}}, {1, 50, 2, 65, 0, 12, {0x20000030, 0x60000000, 0xe000002a, 0x20000043, 0xb0000040, 0xd0000053, 0xd0000022, 0x20000000, 0x60000032, 0x60000043, 0x20000040, 0xe0000042, 0x60000002, 0x80000001, 0x00000020, 0x00000003, 0x40000052, 0x40000040, 0xe0000052, 0xa0000000, 0x80000040, 0x20000001, 0x20000060, 0x80000001, 0x40000042, 0xc0000043, 0x40000022, 0x00000003, 0x40000042, 0xc0000043, 0xc0000022, 0x00000001, 0x40000002, 0xc0000043, 0x40000062, 0x80000001, 0x40000042, 0x40000042, 0x40000002, 0x00000002, 0x00000040, 0x80000002, 0x80000000, 0x80000002, 0x80000040, 0x00000000, 0x80000040, 0x80000000, 0x00000040, 0x80000000, 0x00000040, 0x80000002, 0x00000000, 0x80000000, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000080, 0x00000004, 0x00000009, 0x00000101, 0x00000009, 0x00000012, 0x00000202, 0x0000001a, 0x00000124, 0x0000040c, 0x00000026, 0x0000004a, 0x0000080a, 0x00000060}}, {1, 51, 0, 65, 0, 13, {0xe8000000, 0x0800000c, 0x18000000, 0xb800000a, 0xc8000010, 0x2c000010, 0xf4000014, 0xb4000008, 0x08000000, 0x9800000c, 0xd8000010, 0x08000010, 0xb8000010, 0x98000000, 0x60000000, 0x00000008, 0xc0000000, 0x90000014, 0x10000010, 0xb8000014, 0x28000000, 0x20000010, 0x48000000, 0x08000018, 0x60000000, 0x90000010, 0xf0000010, 0x90000008, 0xc0000000, 0x90000010, 0xf0000010, 0xb0000008, 0x40000000, 0x90000000, 0xf0000010, 0x90000018, 0x60000000, 0x90000010, 0x90000010, 0x90000000, 0x80000000, 0x00000010, 0xa0000000, 0x20000000, 0xa0000000, 0x20000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x20000000, 0x00000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000040, 0x40000002, 0x80000004, 0x80000080, 0x80000006, 0x00000049, 0x00000103, 0x80000009, 0x80000012, 0x80000202}}, {1, 51, 2, 65, 0, 14, {0xa0000003, 0x20000030, 0x60000000, 0xe000002a, 0x20000043, 0xb0000040, 0xd0000053, 0xd0000022, 0x20000000, 0x60000032, 0x60000043, 0x20000040, 0xe0000042, 0x60000002, 0x80000001, 0x00000020, 0x00000003, 0x40000052, 0x40000040, 0xe0000052, 0xa0000000, 0x80000040, 0x20000001, 0x20000060, 0x80000001, 0x40000042, 0xc0000043, 0x40000022, 0x00000003, 0x40000042, 0xc0000043, 0xc0000022, 0x00000001, 0x40000002, 0xc0000043, 0x40000062, 0x80000001, 0x40000042, 0x40000042, 0x40000002, 0x00000002, 0x00000040, 0x80000002, 0x80000000, 0x80000002, 0x80000040, 0x00000000, 0x80000040, 0x80000000, 0x00000040, 0x80000000, 0x00000040, 0x80000002, 0x00000000, 0x80000000, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000080, 0x00000004, 0x00000009, 0x00000101, 0x00000009, 0x00000012, 0x00000202, 0x0000001a, 0x00000124, 0x0000040c, 0x00000026, 0x0000004a, 0x0000080a}}, {1, 52, 0, 65, 0, 15, {0x04000010, 0xe8000000, 0x0800000c, 0x18000000, 0xb800000a, 0xc8000010, 0x2c000010, 0xf4000014, 0xb4000008, 0x08000000, 0x9800000c, 0xd8000010, 0x08000010, 0xb8000010, 0x98000000, 0x60000000, 0x00000008, 0xc0000000, 0x90000014, 0x10000010, 0xb8000014, 0x28000000, 0x20000010, 0x48000000, 0x08000018, 0x60000000, 0x90000010, 0xf0000010, 0x90000008, 0xc0000000, 0x90000010, 0xf0000010, 0xb0000008, 0x40000000, 0x90000000, 0xf0000010, 0x90000018, 0x60000000, 0x90000010, 0x90000010, 0x90000000, 0x80000000, 0x00000010, 0xa0000000, 0x20000000, 0xa0000000, 0x20000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x20000000, 0x00000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000040, 0x40000002, 0x80000004, 0x80000080, 0x80000006, 0x00000049, 0x00000103, 0x80000009, 0x80000012}}, {2, 45, 0, 58, 0, 16, {0xec000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x2c000004, 0xbc000018, 0xb0000010, 0x0000000c, 0xb8000010, 0x08000018, 0x78000010, 0x08000014, 0x70000010, 0xb800001c, 0xe8000000, 0xb0000004, 0x58000010, 0xb000000c, 0x48000000, 0xb0000000, 0xb8000010, 0x98000010, 0xa0000000, 0x00000000, 0x00000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x60000000, 0x00000018, 0xe0000000, 0x90000000, 0x30000010, 0xb0000000, 0x20000000, 0x20000000, 0xa0000000, 0x00000010, 0x80000000, 0x20000000, 0x20000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000041, 0x40000022, 0x80000005, 0xc0000082, 0xc0000046, 0x4000004b, 0x80000107, 0x00000089, 0x00000014, 0x8000024b, 0x0000011b, 0x8000016d, 0x8000041a, 0x000002e4, 0x80000054, 0x00000967}}, {2, 46, 0, 58, 0, 17, {0x2400001c, 0xec000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x2c000004, 0xbc000018, 0xb0000010, 0x0000000c, 0xb8000010, 0x08000018, 0x78000010, 0x08000014, 0x70000010, 0xb800001c, 0xe8000000, 0xb0000004, 0x58000010, 0xb000000c, 0x48000000, 0xb0000000, 0xb8000010, 0x98000010, 0xa0000000, 0x00000000, 0x00000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x60000000, 0x00000018, 0xe0000000, 0x90000000, 0x30000010, 0xb0000000, 0x20000000, 0x20000000, 0xa0000000, 0x00000010, 0x80000000, 0x20000000, 0x20000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000041, 0x40000022, 0x80000005, 0xc0000082, 0xc0000046, 0x4000004b, 0x80000107, 0x00000089, 0x00000014, 0x8000024b, 0x0000011b, 0x8000016d, 0x8000041a, 0x000002e4, 0x80000054}}, {2, 46, 2, 58, 0, 18, {0x90000070, 0xb0000053, 0x30000008, 0x00000043, 0xd0000072, 0xb0000010, 0xf0000062, 0xc0000042, 0x00000030, 0xe0000042, 0x20000060, 0xe0000041, 0x20000050, 0xc0000041, 0xe0000072, 0xa0000003, 0xc0000012, 0x60000041, 0xc0000032, 0x20000001, 0xc0000002, 0xe0000042, 0x60000042, 0x80000002, 0x00000000, 0x00000000, 0x80000000, 0x00000002, 0x00000040, 0x00000000, 0x80000040, 0x80000000, 0x00000040, 0x80000001, 0x00000060, 0x80000003, 0x40000002, 0xc0000040, 0xc0000002, 0x80000000, 0x80000000, 0x80000002, 0x00000040, 0x00000002, 0x80000000, 0x80000000, 0x80000000, 0x00000002, 0x00000040, 0x00000000, 0x80000040, 0x80000002, 0x00000000, 0x80000000, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000080, 0x00000004, 0x00000009, 0x00000105, 0x00000089, 0x00000016, 0x0000020b, 0x0000011b, 0x0000012d, 0x0000041e, 0x00000224, 0x00000050, 0x0000092e, 0x0000046c, 0x000005b6, 0x0000106a, 0x00000b90, 0x00000152}}, {2, 47, 0, 58, 0, 19, {0x20000010, 0x2400001c, 0xec000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x2c000004, 0xbc000018, 0xb0000010, 0x0000000c, 0xb8000010, 0x08000018, 0x78000010, 0x08000014, 0x70000010, 0xb800001c, 0xe8000000, 0xb0000004, 0x58000010, 0xb000000c, 0x48000000, 0xb0000000, 0xb8000010, 0x98000010, 0xa0000000, 0x00000000, 0x00000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x60000000, 0x00000018, 0xe0000000, 0x90000000, 0x30000010, 0xb0000000, 0x20000000, 0x20000000, 0xa0000000, 0x00000010, 0x80000000, 0x20000000, 0x20000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000041, 0x40000022, 0x80000005, 0xc0000082, 0xc0000046, 0x4000004b, 0x80000107, 0x00000089, 0x00000014, 0x8000024b, 0x0000011b, 0x8000016d, 0x8000041a, 0x000002e4}}, {2, 48, 0, 58, 0, 20, {0xbc00001a, 0x20000010, 0x2400001c, 0xec000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x2c000004, 0xbc000018, 0xb0000010, 0x0000000c, 0xb8000010, 0x08000018, 0x78000010, 0x08000014, 0x70000010, 0xb800001c, 0xe8000000, 0xb0000004, 0x58000010, 0xb000000c, 0x48000000, 0xb0000000, 0xb8000010, 0x98000010, 0xa0000000, 0x00000000, 0x00000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x60000000, 0x00000018, 0xe0000000, 0x90000000, 0x30000010, 0xb0000000, 0x20000000, 0x20000000, 0xa0000000, 0x00000010, 0x80000000, 0x20000000, 0x20000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000041, 0x40000022, 0x80000005, 0xc0000082, 0xc0000046, 0x4000004b, 0x80000107, 0x00000089, 0x00000014, 0x8000024b, 0x0000011b, 0x8000016d, 0x8000041a}}, {2, 49, 0, 58, 0, 21, {0x3c000004, 0xbc00001a, 0x20000010, 0x2400001c, 0xec000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x2c000004, 0xbc000018, 0xb0000010, 0x0000000c, 0xb8000010, 0x08000018, 0x78000010, 0x08000014, 0x70000010, 0xb800001c, 0xe8000000, 0xb0000004, 0x58000010, 0xb000000c, 0x48000000, 0xb0000000, 0xb8000010, 0x98000010, 0xa0000000, 0x00000000, 0x00000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x60000000, 0x00000018, 0xe0000000, 0x90000000, 0x30000010, 0xb0000000, 0x20000000, 0x20000000, 0xa0000000, 0x00000010, 0x80000000, 0x20000000, 0x20000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000041, 0x40000022, 0x80000005, 0xc0000082, 0xc0000046, 0x4000004b, 0x80000107, 0x00000089, 0x00000014, 0x8000024b, 0x0000011b, 0x8000016d}}, {2, 49, 2, 58, 0, 22, {0xf0000010, 0xf000006a, 0x80000040, 0x90000070, 0xb0000053, 0x30000008, 0x00000043, 0xd0000072, 0xb0000010, 0xf0000062, 0xc0000042, 0x00000030, 0xe0000042, 0x20000060, 0xe0000041, 0x20000050, 0xc0000041, 0xe0000072, 0xa0000003, 0xc0000012, 0x60000041, 0xc0000032, 0x20000001, 0xc0000002, 0xe0000042, 0x60000042, 0x80000002, 0x00000000, 0x00000000, 0x80000000, 0x00000002, 0x00000040, 0x00000000, 0x80000040, 0x80000000, 0x00000040, 0x80000001, 0x00000060, 0x80000003, 0x40000002, 0xc0000040, 0xc0000002, 0x80000000, 0x80000000, 0x80000002, 0x00000040, 0x00000002, 0x80000000, 0x80000000, 0x80000000, 0x00000002, 0x00000040, 0x00000000, 0x80000040, 0x80000002, 0x00000000, 0x80000000, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000080, 0x00000004, 0x00000009, 0x00000105, 0x00000089, 0x00000016, 0x0000020b, 0x0000011b, 0x0000012d, 0x0000041e, 0x00000224, 0x00000050, 0x0000092e, 0x0000046c, 0x000005b6}}, {2, 50, 0, 65, 0, 23, {0xb400001c, 0x3c000004, 0xbc00001a, 0x20000010, 0x2400001c, 0xec000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x2c000004, 0xbc000018, 0xb0000010, 0x0000000c, 0xb8000010, 0x08000018, 0x78000010, 0x08000014, 0x70000010, 0xb800001c, 0xe8000000, 0xb0000004, 0x58000010, 0xb000000c, 0x48000000, 0xb0000000, 0xb8000010, 0x98000010, 0xa0000000, 0x00000000, 0x00000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x60000000, 0x00000018, 0xe0000000, 0x90000000, 0x30000010, 0xb0000000, 0x20000000, 0x20000000, 0xa0000000, 0x00000010, 0x80000000, 0x20000000, 0x20000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000041, 0x40000022, 0x80000005, 0xc0000082, 0xc0000046, 0x4000004b, 0x80000107, 0x00000089, 0x00000014, 0x8000024b, 0x0000011b}}, {2, 50, 2, 65, 0, 24, {0xd0000072, 0xf0000010, 0xf000006a, 0x80000040, 0x90000070, 0xb0000053, 0x30000008, 0x00000043, 0xd0000072, 0xb0000010, 0xf0000062, 0xc0000042, 0x00000030, 0xe0000042, 0x20000060, 0xe0000041, 0x20000050, 0xc0000041, 0xe0000072, 0xa0000003, 0xc0000012, 0x60000041, 0xc0000032, 0x20000001, 0xc0000002, 0xe0000042, 0x60000042, 0x80000002, 0x00000000, 0x00000000, 0x80000000, 0x00000002, 0x00000040, 0x00000000, 0x80000040, 0x80000000, 0x00000040, 0x80000001, 0x00000060, 0x80000003, 0x40000002, 0xc0000040, 0xc0000002, 0x80000000, 0x80000000, 0x80000002, 0x00000040, 0x00000002, 0x80000000, 0x80000000, 0x80000000, 0x00000002, 0x00000040, 0x00000000, 0x80000040, 0x80000002, 0x00000000, 0x80000000, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000080, 0x00000004, 0x00000009, 0x00000105, 0x00000089, 0x00000016, 0x0000020b, 0x0000011b, 0x0000012d, 0x0000041e, 0x00000224, 0x00000050, 0x0000092e, 0x0000046c}}, {2, 51, 0, 65, 0, 25, {0xc0000010, 0xb400001c, 0x3c000004, 0xbc00001a, 0x20000010, 0x2400001c, 0xec000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x2c000004, 0xbc000018, 0xb0000010, 0x0000000c, 0xb8000010, 0x08000018, 0x78000010, 0x08000014, 0x70000010, 0xb800001c, 0xe8000000, 0xb0000004, 0x58000010, 0xb000000c, 0x48000000, 0xb0000000, 0xb8000010, 0x98000010, 0xa0000000, 0x00000000, 0x00000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x60000000, 0x00000018, 0xe0000000, 0x90000000, 0x30000010, 0xb0000000, 0x20000000, 0x20000000, 0xa0000000, 0x00000010, 0x80000000, 0x20000000, 0x20000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000041, 0x40000022, 0x80000005, 0xc0000082, 0xc0000046, 0x4000004b, 0x80000107, 0x00000089, 0x00000014, 0x8000024b}}, {2, 51, 2, 65, 0, 26, {0x00000043, 0xd0000072, 0xf0000010, 0xf000006a, 0x80000040, 0x90000070, 0xb0000053, 0x30000008, 0x00000043, 0xd0000072, 0xb0000010, 0xf0000062, 0xc0000042, 0x00000030, 0xe0000042, 0x20000060, 0xe0000041, 0x20000050, 0xc0000041, 0xe0000072, 0xa0000003, 0xc0000012, 0x60000041, 0xc0000032, 0x20000001, 0xc0000002, 0xe0000042, 0x60000042, 0x80000002, 0x00000000, 0x00000000, 0x80000000, 0x00000002, 0x00000040, 0x00000000, 0x80000040, 0x80000000, 0x00000040, 0x80000001, 0x00000060, 0x80000003, 0x40000002, 0xc0000040, 0xc0000002, 0x80000000, 0x80000000, 0x80000002, 0x00000040, 0x00000002, 0x80000000, 0x80000000, 0x80000000, 0x00000002, 0x00000040, 0x00000000, 0x80000040, 0x80000002, 0x00000000, 0x80000000, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000080, 0x00000004, 0x00000009, 0x00000105, 0x00000089, 0x00000016, 0x0000020b, 0x0000011b, 0x0000012d, 0x0000041e, 0x00000224, 0x00000050, 0x0000092e}}, {2, 52, 0, 65, 0, 27, {0x0c000002, 0xc0000010, 0xb400001c, 0x3c000004, 0xbc00001a, 0x20000010, 0x2400001c, 0xec000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x2c000004, 0xbc000018, 0xb0000010, 0x0000000c, 0xb8000010, 0x08000018, 0x78000010, 0x08000014, 0x70000010, 0xb800001c, 0xe8000000, 0xb0000004, 0x58000010, 0xb000000c, 0x48000000, 0xb0000000, 0xb8000010, 0x98000010, 0xa0000000, 0x00000000, 0x00000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x60000000, 0x00000018, 0xe0000000, 0x90000000, 0x30000010, 0xb0000000, 0x20000000, 0x20000000, 0xa0000000, 0x00000010, 0x80000000, 0x20000000, 0x20000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000041, 0x40000022, 0x80000005, 0xc0000082, 0xc0000046, 0x4000004b, 0x80000107, 0x00000089, 0x00000014}}, {2, 53, 0, 65, 0, 28, {0xcc000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x3c000004, 0xbc00001a, 0x20000010, 0x2400001c, 0xec000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x2c000004, 0xbc000018, 0xb0000010, 0x0000000c, 0xb8000010, 0x08000018, 0x78000010, 0x08000014, 0x70000010, 0xb800001c, 0xe8000000, 0xb0000004, 0x58000010, 0xb000000c, 0x48000000, 0xb0000000, 0xb8000010, 0x98000010, 0xa0000000, 0x00000000, 0x00000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x60000000, 0x00000018, 0xe0000000, 0x90000000, 0x30000010, 0xb0000000, 0x20000000, 0x20000000, 0xa0000000, 0x00000010, 0x80000000, 0x20000000, 0x20000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000041, 0x40000022, 0x80000005, 0xc0000082, 0xc0000046, 0x4000004b, 0x80000107, 0x00000089}}, {2, 54, 0, 65, 0, 29, {0x0400001c, 0xcc000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x3c000004, 0xbc00001a, 0x20000010, 0x2400001c, 0xec000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x2c000004, 0xbc000018, 0xb0000010, 0x0000000c, 0xb8000010, 0x08000018, 0x78000010, 0x08000014, 0x70000010, 0xb800001c, 0xe8000000, 0xb0000004, 0x58000010, 0xb000000c, 0x48000000, 0xb0000000, 0xb8000010, 0x98000010, 0xa0000000, 0x00000000, 0x00000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x60000000, 0x00000018, 0xe0000000, 0x90000000, 0x30000010, 0xb0000000, 0x20000000, 0x20000000, 0xa0000000, 0x00000010, 0x80000000, 0x20000000, 0x20000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000041, 0x40000022, 0x80000005, 0xc0000082, 0xc0000046, 0x4000004b, 0x80000107}}, {2, 55, 0, 65, 0, 30, {0x00000010, 0x0400001c, 0xcc000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x3c000004, 0xbc00001a, 0x20000010, 0x2400001c, 0xec000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x2c000004, 0xbc000018, 0xb0000010, 0x0000000c, 0xb8000010, 0x08000018, 0x78000010, 0x08000014, 0x70000010, 0xb800001c, 0xe8000000, 0xb0000004, 0x58000010, 0xb000000c, 0x48000000, 0xb0000000, 0xb8000010, 0x98000010, 0xa0000000, 0x00000000, 0x00000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x60000000, 0x00000018, 0xe0000000, 0x90000000, 0x30000010, 0xb0000000, 0x20000000, 0x20000000, 0xa0000000, 0x00000010, 0x80000000, 0x20000000, 0x20000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000041, 0x40000022, 0x80000005, 0xc0000082, 0xc0000046, 0x4000004b}}, {2, 56, 0, 65, 0, 31, {0x2600001a, 0x00000010, 0x0400001c, 0xcc000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x3c000004, 0xbc00001a, 0x20000010, 0x2400001c, 0xec000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x2c000004, 0xbc000018, 0xb0000010, 0x0000000c, 0xb8000010, 0x08000018, 0x78000010, 0x08000014, 0x70000010, 0xb800001c, 0xe8000000, 0xb0000004, 0x58000010, 0xb000000c, 0x48000000, 0xb0000000, 0xb8000010, 0x98000010, 0xa0000000, 0x00000000, 0x00000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x60000000, 0x00000018, 0xe0000000, 0x90000000, 0x30000010, 0xb0000000, 0x20000000, 0x20000000, 0xa0000000, 0x00000010, 0x80000000, 0x20000000, 0x20000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000041, 0x40000022, 0x80000005, 0xc0000082, 0xc0000046}}, {0, 0, 0, 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}}; -void ubc_check(const uint32_t W[80], uint32_t dvmask[1]) -{ - uint32_t mask = ~((uint32_t)(0)); - mask &= (((((W[44] ^ W[45]) >> 29) & 1) - 1) | ~(DV_I_48_0_bit | DV_I_51_0_bit | DV_I_52_0_bit | DV_II_45_0_bit | DV_II_46_0_bit | DV_II_50_0_bit | DV_II_51_0_bit)); - mask &= (((((W[49] ^ W[50]) >> 29) & 1) - 1) | ~(DV_I_46_0_bit | DV_II_45_0_bit | DV_II_50_0_bit | DV_II_51_0_bit | DV_II_55_0_bit | DV_II_56_0_bit)); - mask &= (((((W[48] ^ W[49]) >> 29) & 1) - 1) | ~(DV_I_45_0_bit | DV_I_52_0_bit | DV_II_49_0_bit | DV_II_50_0_bit | DV_II_54_0_bit | DV_II_55_0_bit)); - mask &= ((((W[47] ^ (W[50] >> 25)) & (1 << 4)) - (1 << 4)) | ~(DV_I_47_0_bit | DV_I_49_0_bit | DV_I_51_0_bit | DV_II_45_0_bit | DV_II_51_0_bit | DV_II_56_0_bit)); - mask &= (((((W[47] ^ W[48]) >> 29) & 1) - 1) | ~(DV_I_44_0_bit | DV_I_51_0_bit | DV_II_48_0_bit | DV_II_49_0_bit | DV_II_53_0_bit | DV_II_54_0_bit)); - mask &= (((((W[46] >> 4) ^ (W[49] >> 29)) & 1) - 1) | ~(DV_I_46_0_bit | DV_I_48_0_bit | DV_I_50_0_bit | DV_I_52_0_bit | DV_II_50_0_bit | DV_II_55_0_bit)); - mask &= (((((W[46] ^ W[47]) >> 29) & 1) - 1) | ~(DV_I_43_0_bit | DV_I_50_0_bit | DV_II_47_0_bit | DV_II_48_0_bit | DV_II_52_0_bit | DV_II_53_0_bit)); - mask &= (((((W[45] >> 4) ^ (W[48] >> 29)) & 1) - 1) | ~(DV_I_45_0_bit | DV_I_47_0_bit | DV_I_49_0_bit | DV_I_51_0_bit | DV_II_49_0_bit | DV_II_54_0_bit)); - mask &= (((((W[45] ^ W[46]) >> 29) & 1) - 1) | ~(DV_I_49_0_bit | DV_I_52_0_bit | DV_II_46_0_bit | DV_II_47_0_bit | DV_II_51_0_bit | DV_II_52_0_bit)); - mask &= (((((W[44] >> 4) ^ (W[47] >> 29)) & 1) - 1) | ~(DV_I_44_0_bit | DV_I_46_0_bit | DV_I_48_0_bit | DV_I_50_0_bit | DV_II_48_0_bit | DV_II_53_0_bit)); - mask &= (((((W[43] >> 4) ^ (W[46] >> 29)) & 1) - 1) | ~(DV_I_43_0_bit | DV_I_45_0_bit | DV_I_47_0_bit | DV_I_49_0_bit | DV_II_47_0_bit | DV_II_52_0_bit)); - mask &= (((((W[43] ^ W[44]) >> 29) & 1) - 1) | ~(DV_I_47_0_bit | DV_I_50_0_bit | DV_I_51_0_bit | DV_II_45_0_bit | DV_II_49_0_bit | DV_II_50_0_bit)); - mask &= (((((W[42] >> 4) ^ (W[45] >> 29)) & 1) - 1) | ~(DV_I_44_0_bit | DV_I_46_0_bit | DV_I_48_0_bit | DV_I_52_0_bit | DV_II_46_0_bit | DV_II_51_0_bit)); - mask &= (((((W[41] >> 4) ^ (W[44] >> 29)) & 1) - 1) | ~(DV_I_43_0_bit | DV_I_45_0_bit | DV_I_47_0_bit | DV_I_51_0_bit | DV_II_45_0_bit | DV_II_50_0_bit)); - mask &= (((((W[40] ^ W[41]) >> 29) & 1) - 1) | ~(DV_I_44_0_bit | DV_I_47_0_bit | DV_I_48_0_bit | DV_II_46_0_bit | DV_II_47_0_bit | DV_II_56_0_bit)); - mask &= (((((W[54] ^ W[55]) >> 29) & 1) - 1) | ~(DV_I_51_0_bit | DV_II_47_0_bit | DV_II_50_0_bit | DV_II_55_0_bit | DV_II_56_0_bit)); - mask &= (((((W[53] ^ W[54]) >> 29) & 1) - 1) | ~(DV_I_50_0_bit | DV_II_46_0_bit | DV_II_49_0_bit | DV_II_54_0_bit | DV_II_55_0_bit)); - mask &= (((((W[52] ^ W[53]) >> 29) & 1) - 1) | ~(DV_I_49_0_bit | DV_II_45_0_bit | DV_II_48_0_bit | DV_II_53_0_bit | DV_II_54_0_bit)); - mask &= ((((W[50] ^ (W[53] >> 25)) & (1 << 4)) - (1 << 4)) | ~(DV_I_50_0_bit | DV_I_52_0_bit | DV_II_46_0_bit | DV_II_48_0_bit | DV_II_54_0_bit)); - mask &= (((((W[50] ^ W[51]) >> 29) & 1) - 1) | ~(DV_I_47_0_bit | DV_II_46_0_bit | DV_II_51_0_bit | DV_II_52_0_bit | DV_II_56_0_bit)); - mask &= ((((W[49] ^ (W[52] >> 25)) & (1 << 4)) - (1 << 4)) | ~(DV_I_49_0_bit | DV_I_51_0_bit | DV_II_45_0_bit | DV_II_47_0_bit | DV_II_53_0_bit)); - mask &= ((((W[48] ^ (W[51] >> 25)) & (1 << 4)) - (1 << 4)) | ~(DV_I_48_0_bit | DV_I_50_0_bit | DV_I_52_0_bit | DV_II_46_0_bit | DV_II_52_0_bit)); - mask &= (((((W[42] ^ W[43]) >> 29) & 1) - 1) | ~(DV_I_46_0_bit | DV_I_49_0_bit | DV_I_50_0_bit | DV_II_48_0_bit | DV_II_49_0_bit)); - mask &= (((((W[41] ^ W[42]) >> 29) & 1) - 1) | ~(DV_I_45_0_bit | DV_I_48_0_bit | DV_I_49_0_bit | DV_II_47_0_bit | DV_II_48_0_bit)); - mask &= (((((W[40] >> 4) ^ (W[43] >> 29)) & 1) - 1) | ~(DV_I_44_0_bit | DV_I_46_0_bit | DV_I_50_0_bit | DV_II_49_0_bit | DV_II_56_0_bit)); - mask &= (((((W[39] >> 4) ^ (W[42] >> 29)) & 1) - 1) | ~(DV_I_43_0_bit | DV_I_45_0_bit | DV_I_49_0_bit | DV_II_48_0_bit | DV_II_55_0_bit)); - if (mask & (DV_I_44_0_bit | DV_I_48_0_bit | DV_II_47_0_bit | DV_II_54_0_bit | DV_II_56_0_bit)) - mask &= (((((W[38] >> 4) ^ (W[41] >> 29)) & 1) - 1) | ~(DV_I_44_0_bit | DV_I_48_0_bit | DV_II_47_0_bit | DV_II_54_0_bit | DV_II_56_0_bit)); - mask &= (((((W[37] >> 4) ^ (W[40] >> 29)) & 1) - 1) | ~(DV_I_43_0_bit | DV_I_47_0_bit | DV_II_46_0_bit | DV_II_53_0_bit | DV_II_55_0_bit)); - if (mask & (DV_I_52_0_bit | DV_II_48_0_bit | DV_II_51_0_bit | DV_II_56_0_bit)) - mask &= (((((W[55] ^ W[56]) >> 29) & 1) - 1) | ~(DV_I_52_0_bit | DV_II_48_0_bit | DV_II_51_0_bit | DV_II_56_0_bit)); - if (mask & (DV_I_52_0_bit | DV_II_48_0_bit | DV_II_50_0_bit | DV_II_56_0_bit)) - mask &= ((((W[52] ^ (W[55] >> 25)) & (1 << 4)) - (1 << 4)) | ~(DV_I_52_0_bit | DV_II_48_0_bit | DV_II_50_0_bit | DV_II_56_0_bit)); - if (mask & (DV_I_51_0_bit | DV_II_47_0_bit | DV_II_49_0_bit | DV_II_55_0_bit)) - mask &= ((((W[51] ^ (W[54] >> 25)) & (1 << 4)) - (1 << 4)) | ~(DV_I_51_0_bit | DV_II_47_0_bit | DV_II_49_0_bit | DV_II_55_0_bit)); - if (mask & (DV_I_48_0_bit | DV_II_47_0_bit | DV_II_52_0_bit | DV_II_53_0_bit)) - mask &= (((((W[51] ^ W[52]) >> 29) & 1) - 1) | ~(DV_I_48_0_bit | DV_II_47_0_bit | DV_II_52_0_bit | DV_II_53_0_bit)); - if (mask & (DV_I_46_0_bit | DV_I_49_0_bit | DV_II_45_0_bit | DV_II_48_0_bit)) - mask &= (((((W[36] >> 4) ^ (W[40] >> 29)) & 1) - 1) | ~(DV_I_46_0_bit | DV_I_49_0_bit | DV_II_45_0_bit | DV_II_48_0_bit)); - if (mask & (DV_I_52_0_bit | DV_II_48_0_bit | DV_II_49_0_bit)) - mask &= ((0 - (((W[53] ^ W[56]) >> 29) & 1)) | ~(DV_I_52_0_bit | DV_II_48_0_bit | DV_II_49_0_bit)); - if (mask & (DV_I_50_0_bit | DV_II_46_0_bit | DV_II_47_0_bit)) - mask &= ((0 - (((W[51] ^ W[54]) >> 29) & 1)) | ~(DV_I_50_0_bit | DV_II_46_0_bit | DV_II_47_0_bit)); - if (mask & (DV_I_49_0_bit | DV_I_51_0_bit | DV_II_45_0_bit)) - mask &= ((0 - (((W[50] ^ W[52]) >> 29) & 1)) | ~(DV_I_49_0_bit | DV_I_51_0_bit | DV_II_45_0_bit)); - if (mask & (DV_I_48_0_bit | DV_I_50_0_bit | DV_I_52_0_bit)) - mask &= ((0 - (((W[49] ^ W[51]) >> 29) & 1)) | ~(DV_I_48_0_bit | DV_I_50_0_bit | DV_I_52_0_bit)); - if (mask & (DV_I_47_0_bit | DV_I_49_0_bit | DV_I_51_0_bit)) - mask &= ((0 - (((W[48] ^ W[50]) >> 29) & 1)) | ~(DV_I_47_0_bit | DV_I_49_0_bit | DV_I_51_0_bit)); - if (mask & (DV_I_46_0_bit | DV_I_48_0_bit | DV_I_50_0_bit)) - mask &= ((0 - (((W[47] ^ W[49]) >> 29) & 1)) | ~(DV_I_46_0_bit | DV_I_48_0_bit | DV_I_50_0_bit)); - if (mask & (DV_I_45_0_bit | DV_I_47_0_bit | DV_I_49_0_bit)) - mask &= ((0 - (((W[46] ^ W[48]) >> 29) & 1)) | ~(DV_I_45_0_bit | DV_I_47_0_bit | DV_I_49_0_bit)); - mask &= ((((W[45] ^ W[47]) & (1 << 6)) - (1 << 6)) | ~(DV_I_47_2_bit | DV_I_49_2_bit | DV_I_51_2_bit)); - if (mask & (DV_I_44_0_bit | DV_I_46_0_bit | DV_I_48_0_bit)) - mask &= ((0 - (((W[45] ^ W[47]) >> 29) & 1)) | ~(DV_I_44_0_bit | DV_I_46_0_bit | DV_I_48_0_bit)); - mask &= (((((W[44] ^ W[46]) >> 6) & 1) - 1) | ~(DV_I_46_2_bit | DV_I_48_2_bit | DV_I_50_2_bit)); - if (mask & (DV_I_43_0_bit | DV_I_45_0_bit | DV_I_47_0_bit)) - mask &= ((0 - (((W[44] ^ W[46]) >> 29) & 1)) | ~(DV_I_43_0_bit | DV_I_45_0_bit | DV_I_47_0_bit)); - mask &= ((0 - ((W[41] ^ (W[42] >> 5)) & (1 << 1))) | ~(DV_I_48_2_bit | DV_II_46_2_bit | DV_II_51_2_bit)); - mask &= ((0 - ((W[40] ^ (W[41] >> 5)) & (1 << 1))) | ~(DV_I_47_2_bit | DV_I_51_2_bit | DV_II_50_2_bit)); - if (mask & (DV_I_44_0_bit | DV_I_46_0_bit | DV_II_56_0_bit)) - mask &= ((0 - (((W[40] ^ W[42]) >> 4) & 1)) | ~(DV_I_44_0_bit | DV_I_46_0_bit | DV_II_56_0_bit)); - mask &= ((0 - ((W[39] ^ (W[40] >> 5)) & (1 << 1))) | ~(DV_I_46_2_bit | DV_I_50_2_bit | DV_II_49_2_bit)); - if (mask & (DV_I_43_0_bit | DV_I_45_0_bit | DV_II_55_0_bit)) - mask &= ((0 - (((W[39] ^ W[41]) >> 4) & 1)) | ~(DV_I_43_0_bit | DV_I_45_0_bit | DV_II_55_0_bit)); - if (mask & (DV_I_44_0_bit | DV_II_54_0_bit | DV_II_56_0_bit)) - mask &= ((0 - (((W[38] ^ W[40]) >> 4) & 1)) | ~(DV_I_44_0_bit | DV_II_54_0_bit | DV_II_56_0_bit)); - if (mask & (DV_I_43_0_bit | DV_II_53_0_bit | DV_II_55_0_bit)) - mask &= ((0 - (((W[37] ^ W[39]) >> 4) & 1)) | ~(DV_I_43_0_bit | DV_II_53_0_bit | DV_II_55_0_bit)); - mask &= ((0 - ((W[36] ^ (W[37] >> 5)) & (1 << 1))) | ~(DV_I_47_2_bit | DV_I_50_2_bit | DV_II_46_2_bit)); - if (mask & (DV_I_45_0_bit | DV_I_48_0_bit | DV_II_47_0_bit)) - mask &= (((((W[35] >> 4) ^ (W[39] >> 29)) & 1) - 1) | ~(DV_I_45_0_bit | DV_I_48_0_bit | DV_II_47_0_bit)); - if (mask & (DV_I_48_0_bit | DV_II_48_0_bit)) - mask &= ((0 - ((W[63] ^ (W[64] >> 5)) & (1 << 0))) | ~(DV_I_48_0_bit | DV_II_48_0_bit)); - if (mask & (DV_I_45_0_bit | DV_II_45_0_bit)) - mask &= ((0 - ((W[63] ^ (W[64] >> 5)) & (1 << 1))) | ~(DV_I_45_0_bit | DV_II_45_0_bit)); - if (mask & (DV_I_47_0_bit | DV_II_47_0_bit)) - mask &= ((0 - ((W[62] ^ (W[63] >> 5)) & (1 << 0))) | ~(DV_I_47_0_bit | DV_II_47_0_bit)); - if (mask & (DV_I_46_0_bit | DV_II_46_0_bit)) - mask &= ((0 - ((W[61] ^ (W[62] >> 5)) & (1 << 0))) | ~(DV_I_46_0_bit | DV_II_46_0_bit)); - mask &= ((0 - ((W[61] ^ (W[62] >> 5)) & (1 << 2))) | ~(DV_I_46_2_bit | DV_II_46_2_bit)); - if (mask & (DV_I_45_0_bit | DV_II_45_0_bit)) - mask &= ((0 - ((W[60] ^ (W[61] >> 5)) & (1 << 0))) | ~(DV_I_45_0_bit | DV_II_45_0_bit)); - if (mask & (DV_II_51_0_bit | DV_II_54_0_bit)) - mask &= (((((W[58] ^ W[59]) >> 29) & 1) - 1) | ~(DV_II_51_0_bit | DV_II_54_0_bit)); - if (mask & (DV_II_50_0_bit | DV_II_53_0_bit)) - mask &= (((((W[57] ^ W[58]) >> 29) & 1) - 1) | ~(DV_II_50_0_bit | DV_II_53_0_bit)); - if (mask & (DV_II_52_0_bit | DV_II_54_0_bit)) - mask &= ((((W[56] ^ (W[59] >> 25)) & (1 << 4)) - (1 << 4)) | ~(DV_II_52_0_bit | DV_II_54_0_bit)); - if (mask & (DV_II_51_0_bit | DV_II_52_0_bit)) - mask &= ((0 - (((W[56] ^ W[59]) >> 29) & 1)) | ~(DV_II_51_0_bit | DV_II_52_0_bit)); - if (mask & (DV_II_49_0_bit | DV_II_52_0_bit)) - mask &= (((((W[56] ^ W[57]) >> 29) & 1) - 1) | ~(DV_II_49_0_bit | DV_II_52_0_bit)); - if (mask & (DV_II_51_0_bit | DV_II_53_0_bit)) - mask &= ((((W[55] ^ (W[58] >> 25)) & (1 << 4)) - (1 << 4)) | ~(DV_II_51_0_bit | DV_II_53_0_bit)); - if (mask & (DV_II_50_0_bit | DV_II_52_0_bit)) - mask &= ((((W[54] ^ (W[57] >> 25)) & (1 << 4)) - (1 << 4)) | ~(DV_II_50_0_bit | DV_II_52_0_bit)); - if (mask & (DV_II_49_0_bit | DV_II_51_0_bit)) - mask &= ((((W[53] ^ (W[56] >> 25)) & (1 << 4)) - (1 << 4)) | ~(DV_II_49_0_bit | DV_II_51_0_bit)); - mask &= ((((W[51] ^ (W[50] >> 5)) & (1 << 1)) - (1 << 1)) | ~(DV_I_50_2_bit | DV_II_46_2_bit)); - mask &= ((((W[48] ^ W[50]) & (1 << 6)) - (1 << 6)) | ~(DV_I_50_2_bit | DV_II_46_2_bit)); - if (mask & (DV_I_51_0_bit | DV_I_52_0_bit)) - mask &= ((0 - (((W[48] ^ W[55]) >> 29) & 1)) | ~(DV_I_51_0_bit | DV_I_52_0_bit)); - mask &= ((((W[47] ^ W[49]) & (1 << 6)) - (1 << 6)) | ~(DV_I_49_2_bit | DV_I_51_2_bit)); - mask &= ((((W[48] ^ (W[47] >> 5)) & (1 << 1)) - (1 << 1)) | ~(DV_I_47_2_bit | DV_II_51_2_bit)); - mask &= ((((W[46] ^ W[48]) & (1 << 6)) - (1 << 6)) | ~(DV_I_48_2_bit | DV_I_50_2_bit)); - mask &= ((((W[47] ^ (W[46] >> 5)) & (1 << 1)) - (1 << 1)) | ~(DV_I_46_2_bit | DV_II_50_2_bit)); - mask &= ((0 - ((W[44] ^ (W[45] >> 5)) & (1 << 1))) | ~(DV_I_51_2_bit | DV_II_49_2_bit)); - mask &= ((((W[43] ^ W[45]) & (1 << 6)) - (1 << 6)) | ~(DV_I_47_2_bit | DV_I_49_2_bit)); - mask &= (((((W[42] ^ W[44]) >> 6) & 1) - 1) | ~(DV_I_46_2_bit | DV_I_48_2_bit)); - mask &= ((((W[43] ^ (W[42] >> 5)) & (1 << 1)) - (1 << 1)) | ~(DV_II_46_2_bit | DV_II_51_2_bit)); - mask &= ((((W[42] ^ (W[41] >> 5)) & (1 << 1)) - (1 << 1)) | ~(DV_I_51_2_bit | DV_II_50_2_bit)); - mask &= ((((W[41] ^ (W[40] >> 5)) & (1 << 1)) - (1 << 1)) | ~(DV_I_50_2_bit | DV_II_49_2_bit)); - if (mask & (DV_I_52_0_bit | DV_II_51_0_bit)) - mask &= ((((W[39] ^ (W[43] >> 25)) & (1 << 4)) - (1 << 4)) | ~(DV_I_52_0_bit | DV_II_51_0_bit)); - if (mask & (DV_I_51_0_bit | DV_II_50_0_bit)) - mask &= ((((W[38] ^ (W[42] >> 25)) & (1 << 4)) - (1 << 4)) | ~(DV_I_51_0_bit | DV_II_50_0_bit)); - if (mask & (DV_I_48_2_bit | DV_I_51_2_bit)) - mask &= ((0 - ((W[37] ^ (W[38] >> 5)) & (1 << 1))) | ~(DV_I_48_2_bit | DV_I_51_2_bit)); - if (mask & (DV_I_50_0_bit | DV_II_49_0_bit)) - mask &= ((((W[37] ^ (W[41] >> 25)) & (1 << 4)) - (1 << 4)) | ~(DV_I_50_0_bit | DV_II_49_0_bit)); - if (mask & (DV_II_52_0_bit | DV_II_54_0_bit)) - mask &= ((0 - ((W[36] ^ W[38]) & (1 << 4))) | ~(DV_II_52_0_bit | DV_II_54_0_bit)); - mask &= ((0 - ((W[35] ^ (W[36] >> 5)) & (1 << 1))) | ~(DV_I_46_2_bit | DV_I_49_2_bit)); - if (mask & (DV_I_51_0_bit | DV_II_47_0_bit)) - mask &= ((((W[35] ^ (W[39] >> 25)) & (1 << 3)) - (1 << 3)) | ~(DV_I_51_0_bit | DV_II_47_0_bit)); - if (mask) - { - - if (mask & DV_I_43_0_bit) - if ( - !((W[61] ^ (W[62] >> 5)) & (1 << 1)) || !(!((W[59] ^ (W[63] >> 25)) & (1 << 5))) || !((W[58] ^ (W[63] >> 30)) & (1 << 0))) - mask &= ~DV_I_43_0_bit; - if (mask & DV_I_44_0_bit) - if ( - !((W[62] ^ (W[63] >> 5)) & (1 << 1)) || !(!((W[60] ^ (W[64] >> 25)) & (1 << 5))) || !((W[59] ^ (W[64] >> 30)) & (1 << 0))) - mask &= ~DV_I_44_0_bit; - if (mask & DV_I_46_2_bit) - mask &= ((~((W[40] ^ W[42]) >> 2)) | ~DV_I_46_2_bit); - if (mask & DV_I_47_2_bit) - if ( - !((W[62] ^ (W[63] >> 5)) & (1 << 2)) || !(!((W[41] ^ W[43]) & (1 << 6)))) - mask &= ~DV_I_47_2_bit; - if (mask & DV_I_48_2_bit) - if ( - !((W[63] ^ (W[64] >> 5)) & (1 << 2)) || !(!((W[48] ^ (W[49] << 5)) & (1 << 6)))) - mask &= ~DV_I_48_2_bit; - if (mask & DV_I_49_2_bit) - if ( - !(!((W[49] ^ (W[50] << 5)) & (1 << 6))) || !((W[42] ^ W[50]) & (1 << 1)) || !(!((W[39] ^ (W[40] << 5)) & (1 << 6))) || !((W[38] ^ W[40]) & (1 << 1))) - mask &= ~DV_I_49_2_bit; - if (mask & DV_I_50_0_bit) - mask &= ((((W[36] ^ W[37]) << 7)) | ~DV_I_50_0_bit); - if (mask & DV_I_50_2_bit) - mask &= ((((W[43] ^ W[51]) << 11)) | ~DV_I_50_2_bit); - if (mask & DV_I_51_0_bit) - mask &= ((((W[37] ^ W[38]) << 9)) | ~DV_I_51_0_bit); - if (mask & DV_I_51_2_bit) - if ( - !(!((W[51] ^ (W[52] << 5)) & (1 << 6))) || !(!((W[49] ^ W[51]) & (1 << 6))) || !(!((W[37] ^ (W[37] >> 5)) & (1 << 1))) || !(!((W[35] ^ (W[39] >> 25)) & (1 << 5)))) - mask &= ~DV_I_51_2_bit; - if (mask & DV_I_52_0_bit) - mask &= ((((W[38] ^ W[39]) << 11)) | ~DV_I_52_0_bit); - if (mask & DV_II_46_2_bit) - mask &= ((((W[47] ^ W[51]) << 17)) | ~DV_II_46_2_bit); - if (mask & DV_II_48_0_bit) - if ( - !(!((W[36] ^ (W[40] >> 25)) & (1 << 3))) || !((W[35] ^ (W[40] << 2)) & (1 << 30))) - mask &= ~DV_II_48_0_bit; - if (mask & DV_II_49_0_bit) - if ( - !(!((W[37] ^ (W[41] >> 25)) & (1 << 3))) || !((W[36] ^ (W[41] << 2)) & (1 << 30))) - mask &= ~DV_II_49_0_bit; - if (mask & DV_II_49_2_bit) - if ( - !(!((W[53] ^ (W[54] << 5)) & (1 << 6))) || !(!((W[51] ^ W[53]) & (1 << 6))) || !((W[50] ^ W[54]) & (1 << 1)) || !(!((W[45] ^ (W[46] << 5)) & (1 << 6))) || !(!((W[37] ^ (W[41] >> 25)) & (1 << 5))) || !((W[36] ^ (W[41] >> 30)) & (1 << 0))) - mask &= ~DV_II_49_2_bit; - if (mask & DV_II_50_0_bit) - if ( - !((W[55] ^ W[58]) & (1 << 29)) || !(!((W[38] ^ (W[42] >> 25)) & (1 << 3))) || !((W[37] ^ (W[42] << 2)) & (1 << 30))) - mask &= ~DV_II_50_0_bit; - if (mask & DV_II_50_2_bit) - if ( - !(!((W[54] ^ (W[55] << 5)) & (1 << 6))) || !(!((W[52] ^ W[54]) & (1 << 6))) || !((W[51] ^ W[55]) & (1 << 1)) || !((W[45] ^ W[47]) & (1 << 1)) || !(!((W[38] ^ (W[42] >> 25)) & (1 << 5))) || !((W[37] ^ (W[42] >> 30)) & (1 << 0))) - mask &= ~DV_II_50_2_bit; - if (mask & DV_II_51_0_bit) - if ( - !(!((W[39] ^ (W[43] >> 25)) & (1 << 3))) || !((W[38] ^ (W[43] << 2)) & (1 << 30))) - mask &= ~DV_II_51_0_bit; - if (mask & DV_II_51_2_bit) - if ( - !(!((W[55] ^ (W[56] << 5)) & (1 << 6))) || !(!((W[53] ^ W[55]) & (1 << 6))) || !((W[52] ^ W[56]) & (1 << 1)) || !((W[46] ^ W[48]) & (1 << 1)) || !(!((W[39] ^ (W[43] >> 25)) & (1 << 5))) || !((W[38] ^ (W[43] >> 30)) & (1 << 0))) - mask &= ~DV_II_51_2_bit; - if (mask & DV_II_52_0_bit) - if ( - !(!((W[59] ^ W[60]) & (1 << 29))) || !(!((W[40] ^ (W[44] >> 25)) & (1 << 3))) || !(!((W[40] ^ (W[44] >> 25)) & (1 << 4))) || !((W[39] ^ (W[44] << 2)) & (1 << 30))) - mask &= ~DV_II_52_0_bit; - if (mask & DV_II_53_0_bit) - if ( - !((W[58] ^ W[61]) & (1 << 29)) || !(!((W[57] ^ (W[61] >> 25)) & (1 << 4))) || !(!((W[41] ^ (W[45] >> 25)) & (1 << 3))) || !(!((W[41] ^ (W[45] >> 25)) & (1 << 4)))) - mask &= ~DV_II_53_0_bit; - if (mask & DV_II_54_0_bit) - if ( - !(!((W[58] ^ (W[62] >> 25)) & (1 << 4))) || !(!((W[42] ^ (W[46] >> 25)) & (1 << 3))) || !(!((W[42] ^ (W[46] >> 25)) & (1 << 4)))) - mask &= ~DV_II_54_0_bit; - if (mask & DV_II_55_0_bit) - if ( - !(!((W[59] ^ (W[63] >> 25)) & (1 << 4))) || !(!((W[57] ^ (W[59] >> 25)) & (1 << 4))) || !(!((W[43] ^ (W[47] >> 25)) & (1 << 3))) || !(!((W[43] ^ (W[47] >> 25)) & (1 << 4)))) - mask &= ~DV_II_55_0_bit; - if (mask & DV_II_56_0_bit) - if ( - !(!((W[60] ^ (W[64] >> 25)) & (1 << 4))) || !(!((W[44] ^ (W[48] >> 25)) & (1 << 3))) || !(!((W[44] ^ (W[48] >> 25)) & (1 << 4)))) - mask &= ~DV_II_56_0_bit; - } - - dvmask[0] = mask; -} - -#ifdef SHA1DC_CUSTOM_TRAILING_INCLUDE_UBC_CHECK_C -#include SHA1DC_CUSTOM_TRAILING_INCLUDE_UBC_CHECK_C -#endif diff --git a/vendor/github.com/pjbgf/sha1cd/cgo/ubc_check.h b/vendor/github.com/pjbgf/sha1cd/cgo/ubc_check.h deleted file mode 100644 index a8863faf46..0000000000 --- a/vendor/github.com/pjbgf/sha1cd/cgo/ubc_check.h +++ /dev/null @@ -1,64 +0,0 @@ -/*** - * Copyright 2017 Marc Stevens , Dan Shumow - * Distributed under the MIT Software License. - * See accompanying file LICENSE.txt or copy at - * https://opensource.org/licenses/MIT - ***/ - -// Originally from: https://github.com/cr-marcstevens/sha1collisiondetection - -/* -// this file was generated by the 'parse_bitrel' program in the tools section -// using the data files from directory 'tools/data/3565' -// -// sha1_dvs contains a list of SHA-1 Disturbance Vectors (DV) to check -// dvType, dvK and dvB define the DV: I(K,B) or II(K,B) (see the paper) -// dm[80] is the expanded message block XOR-difference defined by the DV -// testt is the step to do the recompression from for collision detection -// maski and maskb define the bit to check for each DV in the dvmask returned by ubc_check -// -// ubc_check takes as input an expanded message block and verifies the unavoidable bitconditions for all listed DVs -// it returns a dvmask where each bit belonging to a DV is set if all unavoidable bitconditions for that DV have been met -// thus one needs to do the recompression check for each DV that has its bit set -*/ - -#ifndef SHA1DC_UBC_CHECK_H -#define SHA1DC_UBC_CHECK_H - -#if defined(__cplusplus) -extern "C" -{ -#endif - -#ifndef SHA1DC_NO_STANDARD_INCLUDES -#include -#endif - -#define DVMASKSIZE 1 - typedef struct - { - int dvType; - int dvK; - int dvB; - int testt; - int maski; - int maskb; - uint32_t dm[80]; - } dv_info_t; - extern dv_info_t sha1_dvs[]; - void ubc_check(const uint32_t W[80], uint32_t dvmask[DVMASKSIZE]); - -#define DOSTORESTATE58 -#define DOSTORESTATE65 - -#define CHECK_DVMASK(_DVMASK) (0 != _DVMASK[0]) - -#if defined(__cplusplus) -} -#endif - -#ifdef SHA1DC_CUSTOM_TRAILING_INCLUDE_UBC_CHECK_H -#include SHA1DC_CUSTOM_TRAILING_INCLUDE_UBC_CHECK_H -#endif - -#endif diff --git a/vendor/golang.org/x/crypto/ssh/test/sshd_test_pw.c b/vendor/golang.org/x/crypto/ssh/test/sshd_test_pw.c deleted file mode 100644 index 2794a563a4..0000000000 --- a/vendor/golang.org/x/crypto/ssh/test/sshd_test_pw.c +++ /dev/null @@ -1,173 +0,0 @@ -// Copyright 2017 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// sshd_test_pw.c -// Wrapper to inject test password data for sshd PAM authentication -// -// This wrapper implements custom versions of getpwnam, getpwnam_r, -// getspnam and getspnam_r. These functions first call their real -// libc versions, then check if the requested user matches test user -// specified in env variable TEST_USER and if so replace the password -// with crypted() value of TEST_PASSWD env variable. -// -// Compile: -// gcc -Wall -shared -o sshd_test_pw.so -fPIC sshd_test_pw.c -// -// Compile with debug: -// gcc -DVERBOSE -Wall -shared -o sshd_test_pw.so -fPIC sshd_test_pw.c -// -// Run sshd: -// LD_PRELOAD="sshd_test_pw.so" TEST_USER="..." TEST_PASSWD="..." sshd ... - -// +build ignore - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include - -#ifdef VERBOSE -#define DEBUG(X...) fprintf(stderr, X) -#else -#define DEBUG(X...) while (0) { } -#endif - -/* crypt() password */ -static char * -pwhash(char *passwd) { - return strdup(crypt(passwd, "$6$")); -} - -/* Pointers to real functions in libc */ -static struct passwd * (*real_getpwnam)(const char *) = NULL; -static int (*real_getpwnam_r)(const char *, struct passwd *, char *, size_t, struct passwd **) = NULL; -static struct spwd * (*real_getspnam)(const char *) = NULL; -static int (*real_getspnam_r)(const char *, struct spwd *, char *, size_t, struct spwd **) = NULL; - -/* Cached test user and test password */ -static char *test_user = NULL; -static char *test_passwd_hash = NULL; - -static void -init(void) { - /* Fetch real libc function pointers */ - real_getpwnam = dlsym(RTLD_NEXT, "getpwnam"); - real_getpwnam_r = dlsym(RTLD_NEXT, "getpwnam_r"); - real_getspnam = dlsym(RTLD_NEXT, "getspnam"); - real_getspnam_r = dlsym(RTLD_NEXT, "getspnam_r"); - - /* abort if env variables are not defined */ - if (getenv("TEST_USER") == NULL || getenv("TEST_PASSWD") == NULL) { - fprintf(stderr, "env variables TEST_USER and TEST_PASSWD are missing\n"); - abort(); - } - - /* Fetch test user and test password from env */ - test_user = strdup(getenv("TEST_USER")); - test_passwd_hash = pwhash(getenv("TEST_PASSWD")); - - DEBUG("sshd_test_pw init():\n"); - DEBUG("\treal_getpwnam: %p\n", real_getpwnam); - DEBUG("\treal_getpwnam_r: %p\n", real_getpwnam_r); - DEBUG("\treal_getspnam: %p\n", real_getspnam); - DEBUG("\treal_getspnam_r: %p\n", real_getspnam_r); - DEBUG("\tTEST_USER: '%s'\n", test_user); - DEBUG("\tTEST_PASSWD: '%s'\n", getenv("TEST_PASSWD")); - DEBUG("\tTEST_PASSWD_HASH: '%s'\n", test_passwd_hash); -} - -static int -is_test_user(const char *name) { - if (test_user != NULL && strcmp(test_user, name) == 0) - return 1; - return 0; -} - -/* getpwnam */ - -struct passwd * -getpwnam(const char *name) { - struct passwd *pw; - - DEBUG("sshd_test_pw getpwnam(%s)\n", name); - - if (real_getpwnam == NULL) - init(); - if ((pw = real_getpwnam(name)) == NULL) - return NULL; - - if (is_test_user(name)) - pw->pw_passwd = strdup(test_passwd_hash); - - return pw; -} - -/* getpwnam_r */ - -int -getpwnam_r(const char *name, - struct passwd *pwd, - char *buf, - size_t buflen, - struct passwd **result) { - int r; - - DEBUG("sshd_test_pw getpwnam_r(%s)\n", name); - - if (real_getpwnam_r == NULL) - init(); - if ((r = real_getpwnam_r(name, pwd, buf, buflen, result)) != 0 || *result == NULL) - return r; - - if (is_test_user(name)) - pwd->pw_passwd = strdup(test_passwd_hash); - - return 0; -} - -/* getspnam */ - -struct spwd * -getspnam(const char *name) { - struct spwd *sp; - - DEBUG("sshd_test_pw getspnam(%s)\n", name); - - if (real_getspnam == NULL) - init(); - if ((sp = real_getspnam(name)) == NULL) - return NULL; - - if (is_test_user(name)) - sp->sp_pwdp = strdup(test_passwd_hash); - - return sp; -} - -/* getspnam_r */ - -int -getspnam_r(const char *name, - struct spwd *spbuf, - char *buf, - size_t buflen, - struct spwd **spbufp) { - int r; - - DEBUG("sshd_test_pw getspnam_r(%s)\n", name); - - if (real_getspnam_r == NULL) - init(); - if ((r = real_getspnam_r(name, spbuf, buf, buflen, spbufp)) != 0) - return r; - - if (is_test_user(name)) - spbuf->sp_pwdp = strdup(test_passwd_hash); - - return r; -} diff --git a/vendor/golang.org/x/tools/go/loader/testdata/issue46877/x.h b/vendor/golang.org/x/tools/go/loader/testdata/issue46877/x.h deleted file mode 100644 index 9fc115b35f..0000000000 --- a/vendor/golang.org/x/tools/go/loader/testdata/issue46877/x.h +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2021 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -typedef int myint; diff --git a/vendor/modules.txt b/vendor/modules.txt index eccd056c7b..602fe075a2 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,6 +1,9 @@ # dario.cat/mergo v1.0.0 ## explicit; go 1.13 dario.cat/mergo +# github.com/360EntSecGroup-Skylar/excelize v1.4.1 +## explicit +github.com/360EntSecGroup-Skylar/excelize # github.com/BurntSushi/toml v1.3.2 ## explicit; go 1.16 github.com/BurntSushi/toml @@ -536,6 +539,9 @@ github.com/modern-go/concurrent # github.com/modern-go/reflect2 v1.0.2 ## explicit; go 1.12 github.com/modern-go/reflect2 +# github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 +## explicit +github.com/mohae/deepcopy # github.com/nicksnyder/go-i18n/v2 v2.4.0 ## explicit; go 1.18 github.com/nicksnyder/go-i18n/v2/i18n