Documentation ¶
Index ¶
- Variables
- type CsvReader
- func (c *CsvReader) Close()
- func (c *CsvReader) ReadAll(encoding encoding.Encoding) ([][]string, error)
- func (c *CsvReader) ReadAllJson(encoding encoding.Encoding) ([]map[string]string, error)
- func (c *CsvReader) ReadGBKAll() ([][]string, error)
- func (c *CsvReader) ReadGBKLine(lineDataFunc func(record []string) error) error
- func (c *CsvReader) ReadLine(encoding encoding.Encoding, lineDataFunc func(record []string) error) error
- func (c *CsvReader) ReadLineJson(encoding encoding.Encoding, lineDataFunc func(record map[string]string) error) error
- func (c *CsvReader) ReadTitles(encoding encoding.Encoding) ([]string, error)
- func (c *CsvReader) ReadUTF16All() ([][]string, error)
- func (c *CsvReader) ReadUTF16Line(lineDataFunc func(record []string) error) error
- func (c *CsvReader) ReadUTF8All() ([][]string, error)
- func (c *CsvReader) ReadUTF8Line(lineDataFunc func(record []string) error) error
- type CsvWriter
- func (x *CsvWriter) AppendData(data []string) *CsvWriter
- func (x *CsvWriter) AppendRows(data [][]string) *CsvWriter
- func (c *CsvWriter) AppendToCSV(data [][]string) error
- func (c *CsvWriter) Close()
- func (c *CsvWriter) GetWriter() (*csv.Writer, error)
- func (x *CsvWriter) Output(w io.Writer) (err error)
- func (x *CsvWriter) OutputForGin(ctx *gin.Context, filename string) (err error)
- func (x *CsvWriter) OutputResponseWriter(w http.ResponseWriter, filename string) (err error)
- func (c *CsvWriter) SetTitles(titles []string)
- func (c *CsvWriter) WriteData(records [][]string) error
- func (c *CsvWriter) WriteLine(record []string) error
- type XlsxRead
- type XlsxWrite
- func (x *XlsxWrite) AppendData(data []interface{}) *XlsxWrite
- func (x *XlsxWrite) AppendRows(data [][]interface{}) *XlsxWrite
- func (x *XlsxWrite) Output(w io.Writer) (err error)
- func (x *XlsxWrite) OutputForGin(ctx *gin.Context, filename string) (err error)
- func (x *XlsxWrite) OutputResponseWriter(w http.ResponseWriter, filename string) (err error)
- func (x *XlsxWrite) Save2File(filename string) (err error)
- func (x *XlsxWrite) SetSheetName(sheetName string) *XlsxWrite
- func (x *XlsxWrite) SetTitles(titles []string) *XlsxWrite
Constants ¶
This section is empty.
Variables ¶
View Source
var ( UTF8 = unicode.UTF8 UTF8BOM = unicode.UTF8BOM GBK = simplifiedchinese.GBK //UTF16 有很多种 参考 unicode包 UTF16 = unicode.UTF16(unicode.LittleEndian, unicode.ExpectBOM) )
常用文件编码 unicode.UTF8, unicode.UTF16(BigEndian, UseBOM), unicode.UTF16(BigEndian, IgnoreBOM), unicode.UTF16(LittleEndian, IgnoreBOM), 常用文件编码需要用
View Source
var ( BOM_UTF8 = []byte{0xEF, 0xBB, 0xBF} BOM_UTF16 = []byte{0xFF, 0xFE} )
常用文件编码写入bom头部
Functions ¶
This section is empty.
Types ¶
type CsvReader ¶ added in v1.2.131
type CsvReader struct { FilePath string Comma rune //csv 列分割符 // contains filtered or unexported fields }
func NewCsvReader ¶ added in v1.2.125
comma 默认传 ','
func (*CsvReader) ReadAllJson ¶ added in v1.2.131
第一行作为字段名称,后续行数据转换为json数据一次性返回所有数据
func (*CsvReader) ReadGBKAll ¶ added in v1.2.131
func (*CsvReader) ReadGBKLine ¶ added in v1.2.131
func (*CsvReader) ReadLineJson ¶ added in v1.2.131
func (c *CsvReader) ReadLineJson(encoding encoding.Encoding, lineDataFunc func(record map[string]string) error) error
第一行作为字段名称,后续行数据转换为json数据,一行回调一个json数据
func (*CsvReader) ReadTitles ¶ added in v1.2.161
func (*CsvReader) ReadUTF16All ¶ added in v1.2.131
func (*CsvReader) ReadUTF16Line ¶ added in v1.2.131
func (*CsvReader) ReadUTF8All ¶ added in v1.2.131
type CsvWriter ¶ added in v1.2.141
type CsvWriter struct { FilePath string Comma rune //csv 列分割符 encoding.Encoding // contains filtered or unexported fields }
func NewCsvWriter ¶ added in v1.2.161
func NewCsvWriterNoneFile ¶ added in v1.2.165
不需要创建本地文件, 只写入数据。如:网络IO
func (*CsvWriter) AppendData ¶ added in v1.2.161
func (*CsvWriter) AppendRows ¶ added in v1.2.161
func (*CsvWriter) AppendToCSV ¶ added in v1.2.161
AppendToCSV appends data to an existing CSV file
func (*CsvWriter) OutputForGin ¶ added in v1.2.161
func (*CsvWriter) OutputResponseWriter ¶ added in v1.2.161
func (x *CsvWriter) OutputResponseWriter(w http.ResponseWriter, filename string) (err error)
func (*CsvWriter) WriteLine ¶ added in v1.2.161
func TestCsvWriter(t *testing.T) { csvWriter, err := goxlsx.NewCsvWriter("test.csv", ',') if err != nil { golog.Error(err) return } // 准备要写入的记录 records := [][]string{ {"Alice", "30", "New York"}, {"Bob", "25", "Los Angeles"}, {"Charlie", "35", "Chicago"}, } titles := []string{"Name", "Age", "City"} csvWriter.SetTitles(titles) defer csvWriter.Close() for _, record := range records { err = csvWriter.WriteLine(record) if err != nil { golog.Error(err) } } }
逐行写入, 需要手动调用 c.Close()
type XlsxRead ¶ added in v1.2.122
type XlsxRead struct {
FilePath string
}
需要扩展按行读取文件
func (*XlsxRead) ReadBySheet ¶ added in v1.2.142
type XlsxWrite ¶ added in v1.2.116
扩展需要append to file 功能
func (*XlsxWrite) AppendData ¶ added in v1.2.116
func (*XlsxWrite) AppendRows ¶ added in v1.2.116
func (*XlsxWrite) OutputForGin ¶ added in v1.2.117
func (*XlsxWrite) OutputResponseWriter ¶ added in v1.2.161
func (x *XlsxWrite) OutputResponseWriter(w http.ResponseWriter, filename string) (err error)
func (*XlsxWrite) SetSheetName ¶ added in v1.2.116
Click to show internal directories.
Click to hide internal directories.