Code Monkey home page Code Monkey logo

xlsx's Introduction

Xlsx2Go

Build Status Code Coverage Go Report Card GoDoc License FOSSA Status Donate

package main

import (
	"github.com/plandem/xlsx"
	"github.com/plandem/xlsx/format/conditional"
	"github.com/plandem/xlsx/format/conditional/rule"
	"github.com/plandem/xlsx/format/styles"
)

func main() {
	xl := xlsx.New()
	defer xl.Close()

	//create a new sheet
	sheet := xl.AddSheet("The first sheet")

	//access by ref
	cell := sheet.CellByRef("A2")

	//set value
	cell.SetValue("Easy Peasy")

	//set cool styles
	cell.SetStyles(styles.New(
		styles.Font.Bold,
		styles.Font.Color("#ff0000"),
		styles.Fill.Type(styles.PatternTypeSolid),
		styles.Fill.Color("#ffff00"),
		styles.Border.Color("#009000"),
		styles.Border.Type(styles.BorderStyleMedium),
	))

	//add comment
	cell.SetComment("No Comment!")

	//add hyperlink
	sheet.CellByRef("A4").SetValueWithHyperlink("wikipedia", "http://google.com")

	//merge cells
	sheet.RangeByRef("A6:A7").Merge()
	sheet.CellByRef("A6").SetValue("merged cell")

	//iterating
	for iRow := 1; iRow < 7; iRow++ {
		//access by indexes
		cell := sheet.Cell(1, iRow)
		cell.SetValue(iRow)
	}

	//add conditional formatting
	sheet.AddConditional(conditional.New(
		conditional.AddRule(
			rule.Value.Between(1, 3, styles.New(
				styles.Font.Bold,
				styles.Font.Color("#ff0000"),
			)),
		),
		conditional.AddRule(
			rule.IconSet.Type(rule.IconSetType3Arrows),
		),
	), "B2:B7")

	xl.SaveAs("./foo.xlsx")
}

Documentation

Roadmap

  • sheet: copy
  • sheet: custom filters
  • sheet: streaming
  • merged cells: merge/split for ranges, cols, rows
  • hyperlinks: for cells, ranges, cols, rows
  • range: copy
  • row: copy
  • col: copy
  • cell: comments
  • cell: formulas
  • cell: typed getter/setter for values
  • other: conditional formatting
  • other: rich texts
  • other: drawing
  • other: more optimization
  • other: more tests

Contribution

  • To prevent mess, sources have strict separation of markup and functionality. Document that describes OOXML is quite huge (about 6K pages), but the same time - functionality is not.
  • All markup resides inside of 'ml' folders, only marshal/unmarshal is allowed here, no any functionality.
  • Not every 'ml object' has related 'functional object' and vice versa.
  • If you want some functionality, then wrap 'ml object' and do what you want.

OOXML edition

XML is compliant with part 1 of the 5th edition of the ECMA-376 Standard for Office Open XML

License

FOSSA Status

xlsx's People

Contributors

fossabot avatar plandem avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xlsx's Issues

Closing sheet does not free memory

Hi,
I am trying to write a file with 200+ sheets of 10k+ rows of data and memory consumption is very high (around 7gb)
I tried stream writing data but it still takes too much ram (~700mb) even if a manually close sheets with sheet.Close() after writing all data which seems to not do anything

I checked if combination of saving file and reopening it for new sheet would help and it did (peak memory consumption was 70mb), but each sheet was writing slower and slower due to re-reading all data from file

Can there be a hybrid solution where I can manually close current sheet and free the memory without closing file?

How to retrieve style for existing data

There's good support for setting styles, but I'm having trouble getting styles for existing data.

I need to see if a cell has bold style, which I believe is in DiffStyle accessed by Info.styleInfo (not public).

I tried something like this:

styleID := sheet.Cell(c, r).Styles()
styleInfo := xl.ResolveStyles(styleID)

But I couldn't access any members of Info struct because they are not public. Is there another way to do this?

Border

Thanks for the work you've done. Tell me how to work with borders and center alignment.

index out of range [17] with length 17

17 is the original number of columns the xlsx file has.

xl, err := xlsx.Open('my_file.xslx)
...

sheet := xl.Sheet(0)
...

colCount,_ := sheet.Dimension()
fmt.Println(colCount) // 17
...

sheet.InsertCol(17).Cell(0)
xl.Save()
fmt.Println(sheet.Dimension()) // 18, 132
...

for rows := sheet.Rows(); rows.HasNext(); {
		iRow, row := rows.Next()
                row.Cell(17).SetValue("testing123") // panic: runtime error: index out of range [17] with length 17
}

in sheet_readwrite.go I have tested the following:

func (s *sheetReadWrite) Cell(colIndex, rowIndex int) *Cell {
	s.expandIfRequired(colIndex, rowIndex)

	colIndex, rowIndex, _ = s.mergedCells.Resolve(colIndex, rowIndex)
	fmt.Println("LENGTH:", len(s.ml.SheetData[rowIndex].Cells)) // prints 17 inconsistently
	data := s.ml.SheetData[rowIndex].Cells[colIndex]

	//if there is no any data for this cell, then create it
	if data == nil {
		data = &ml.Cell{
			Ref: types.CellRefFromIndexes(colIndex, rowIndex),
		}

		s.ml.SheetData[rowIndex].Cells[colIndex] = data
	}

	return &Cell{ml: data, sheet: s.sheetInfo}
}

Support for ECMAScript module

Hello, I'm opening this issue because I did not find other discussions about that, please redirect me on the proper issue if you are already discussing it. I was looking for any solution for the Angular 10 warnings (CommonJS or AMD dependencies can cause optimization bailouts.), rather that simply ignore them by configuring allowedCommonJsDependencies in angular.json.
I realized that a ECMAScript module would be needed to make Angular happy. Is there any plan to build xlsx in that way?

Thank you a lot for the support

Set column width when using streaming

Hi, I am trying to writing file with a lot of rows (from 200k to 1m) using streaming mode.

Writing cell with style is ok but when I start set width for column, it return panic with message not supported.

I have read the docs and can't find it. Is there anyway I can keep using stream writing and set column width?

Thank you.

p/s: is there an option to freeze top row or first column?

Get text value from shape

Hi man,

how to get text value from a shape like this,
shape

i hope you create a func to get value from shape,

thanks,

file can not save

func T2(){
	xl, err := xlsx.Open("./foo1.xlsx")
	if err != nil {
		fmt.Println(err)
	}
	defer xl.Close()
	sheet0 := xl.Sheet(0)

	sheet0.CellByRef("A2").SetText("test")

	if err = xl.Save(); err != nil {
		fmt.Println(err)
	}
}
 

ERR:

rename foo1.xlsx406411239 ./foo1.xlsx: Access is denied.

I can not save to file,but it can be saved as new file with new file name.

I run it on windows machine ,go version 1.14.2

Consider preallocating slice

I noticed when looking for performance optimisation that you could preallocate some slices for better performance.

xlsx/internal/hash/reserved.go:14:2: Consider preallocating result (prealloc)
var result []string

xlsx/internal/ml/primitives/bounds_list.go:12:2: Consider preallocating list (prealloc)
var list []Bounds
^
xlsx/internal/ml/primitives/bounds_list.go:28:2: Consider preallocating refs (prealloc)
var refs []string

Read more here:
https://github.com/alexkohler/prealloc

How to save the file correctly?

If call xl.Save before xl.Close:
rename 测试.xlsx950735883 测试.xlsx: Access is denied.

If call xl.Save after xl.Close:
Got a invalid file.

SetHyperlink in the second sheet causing file format errors.

demo.xlsx

SetHyperlink in the first sheet works fine, but not fine in the second sheet.

Open with MS Office 2016:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
	<logFileName>error208200_01.xml</logFileName>
	<summary>在文件“C:\msys64\home\ofunc_7kwo01e\go\src\test\xlsx\demo.xlsx”中检测到错误</summary>
	<additionalInfo>
		<info>Excel 已完成文件级验证和修复。此工作簿的某些部分可能已被修复或丢弃。</info>
	</additionalInfo>
	<repairedParts>
		<repairedPart>已修复的部件: 部件 /xl/worksheets/sheet2.xml。</repairedPart>
	</repairedParts>
</recoveryLog>

InsertRow (for sheetReadWrite)

Hi,

Given the following example: https://play.golang.org/p/G6QwfVo8CFb
which instantiates a new doc, with a blank new sheet, my expectation when invoking InsertRow twice with index 0 was the first two rows being populated with the text.

It appears that the cell pointers are still somehow pegged to the old row: the text appears on the 3rd row.

Please advise if the approach is incorrect, and another approach is necessary when creating documents from scratch (maybe an example in the readme).

Cheers,
silviu

Results of related formulas are not updated.

Hello! Modify an existing xlsx file and save it. However, the calculation results of related formulas are not updated.
There is a simple solution: clear calcId in xl/workbook.xml.
It is recommended to provide an method of Spreadsheet for doing this.

undefined: ml.Name

go/src/github.com/plandem/xlsx/internal/ml/shared_strings.go:10:14: undefined: ml.Name

There is RIDName but no Name.

Reading data formatted as date always returns numbers

Hi,

I'm trying to use the library to process very large files and they contain date columns. When reading the values, I'm always getting numbers (the underlying numeric value for the date). Since I don't know in advance what's the data type for a particular column, I'd like to be able to identify it from the formatting.

I tried using cell.Type() == types.CellTypeDate() to decide whether I could explicitly get the value parsed to Time (with the Date function) but it's always returning false. I then tried to get the style ID and use the style sheet to get the info and check whether it's a date, but then I saw that this method is not implemented.

xlsx/style_sheet.go

Lines 214 to 227 in 4538b54

func (ss *styleSheet) resolveDirectStyle(id ml.DirectStyleID) *styles.Info {
if id == 0 {
return nil
}
panic(errorNotSupported)
//cellStyle := ss.ml.CellXfs.Items[id]
//style := &styles.Info{}
//_ = cellStyle
//TODO: Populate format.Info with required information
//return style
}

Is there a way I can identify dates right now? If not, can you point me to how I can solve this issue so I can send a pull request?

Thanks,
Demontiê

Stream mutation

I'm trying to add columns to a sheet opened in stream mode, and then add a value to those cells added, but adding new columns does not seem propagate in all functions...

here is my example:

sheetNumber := 0
xl, _ := xlsx.Open("my_file.xlsx")
sheet := xl.Sheet(sheetNumber, xlsx.SheetModeStream)
defer sheet.Close()

colCount, _ := sheet.Dimension()
fmt.Println(colCount) // prints 6

addMoreColumns(xl, sheetNumber)

colCount, _ = sheet.Dimension() // update count after adding columns
fmt.Println(colCount) // prints 6, again (should be more)

func addMoreColumns(xl *xlsx.Spreadsheet, sheetNumber int) {
   sheet := xlsx.Sheet(sheetNumber)
   newColIndex := 6
   rowIndex := 0
   sheet.InsertCol(newColIndex).Cell(rowIndex)
}

maligned structs

We could optimise memory allocation by ordering the struct by bytes taken.

Read more here:
https://medium.com/@felipedutratine/how-to-organize-the-go-struct-in-order-to-save-memory-c78afcf59ec2

ooxml/vml/css/css.go:37:12: struct of size 184 bytes could be of size 176 bytes (maligned)
type Style struct {
           ^
xlsx/internal/ml/style_sheet.go:173:20: struct of size 56 bytes could be of size 40 bytes (maligned)
type CellAlignment struct {
                   ^
xlsx/internal/ml/workbook.go:44:17: struct of size 48 bytes could be of size 40 bytes (maligned)
type WorkbookPr struct {
                ^
xlsx/internal/ml/workbook.go:66:15: struct of size 80 bytes could be of size 72 bytes (maligned)
type BookView struct {
              ^
xlsx/internal/ml/worksheet.go:89:11: struct of size 96 bytes could be of size 88 bytes (maligned)
type Cell struct {
          ^
xlsx/internal/ml/worksheet.go:103:18: struct of size 128 bytes could be of size 104 bytes (maligned)
type CellFormula struct {
                 ^
xlsx/internal/ml/worksheet.go:168:22: struct of size 128 bytes could be of size 104 bytes (maligned)
type ConditionalRule struct {
                     ^
xlsx/internal/ml/worksheet.go:190:21: struct of size 40 bytes could be of size 32 bytes (maligned)
type ConditionValue struct {
                    ^
ooxml/vml/vml_test.go:122:18: struct of size 96 bytes could be of size 88 bytes (maligned)
	type ClientData struct {
	                ^
xlsx/sheet_info.go:18:16: struct of size 536 bytes could be of size 528 bytes (maligned)

ineffectual assignment

xlsx/hyperlinks.go:82:3

rid is not used as it is reassigned at the if statement

		//lookup for already existing targets to get RID
		rid := h.sheet.relationships.GetIdByTarget(string(hyperlink.RID))

		//looks like target is new, let's create it and use
		if rid = h.sheet.relationships.GetIdByTarget(string(hyperlink.RID)); len(rid) == 0 {
			_, rid = h.sheet.relationships.AddLink(internal.RelationTypeHyperlink, string(hyperlink.RID))
		}

xlsx/style_sheet.go:309:2

XfId := ml.NamedStyleID(0) is assigned and not used and than reassigned with XfId = ss.addNamedStyleIfRequired(namedInfo, style)

	XfId := ml.NamedStyleID(0)
	style := ml.Style{
		FontId:            fontID,
		FillId:            fillID,
		BorderId:          borderID,
		NumFmtId:          numID,
		Alignment:         alignment,
		Protection:        protection,
		ApplyFont:         fontID > 0,
		ApplyBorder:       borderID > 0,
		ApplyFill:         fillID > 0,
		ApplyNumberFormat: numID > 0,
		ApplyAlignment:    alignment != nil,
		ApplyProtection:   protection != nil,
	}

	//add named style if required and get related XfId
	XfId = ss.addNamedStyleIfRequired(namedInfo, style)```

Error "Index out of range" for some files (excelize can read its)

I run my script

package main

import (
    "fmt"
    "github.com/plandem/xlsx"
)

func main() {
    xl, err := xlsx.Open("goserver/mser/go/Аналитика по МКД_clean.xlsx")
    if err != nil {
        panic(err)
    }
    defer xl.Close()
    fmt.Println(xl.GetSheetNames())
    fmt.Println(xl.Sheet(0))
}

And get an error:

user@c107 ~ $ go run goserver/mser/go/test4.go 
[МКД Организации conf]
panic: runtime error: index out of range

goroutine 1 [running]:
github.com/plandem/xlsx.(*sheetReadWrite).expandOnInit(0xc42000c0f8)
	/home/user/goserver/src/github.com/plandem/xlsx/sheet_readwrite.go:293 +0x601
github.com/plandem/xlsx.(*sheetReadWrite).(github.com/plandem/xlsx.expandOnInit)-fm()
	/home/user/goserver/src/github.com/plandem/xlsx/sheet_readwrite.go:394 +0x2a
github.com/plandem/ooxml.(*PackageFile).LoadIfRequired(0xc4200846e0, 0xc420111eb8)
	/home/user/goserver/src/github.com/plandem/ooxml/package_file.go:88 +0x9a
github.com/plandem/xlsx.(*sheetReadWrite).afterOpen(0xc42000c0f8)
	/home/user/goserver/src/github.com/plandem/xlsx/sheet_readwrite.go:394 +0x54
github.com/plandem/xlsx.(*Spreadsheet).Sheet(0xc420084370, 0x0, 0x1, 0x25)
	/home/user/goserver/src/github.com/plandem/xlsx/spreadsheet.go:63 +0xad
main.main()
	/home/user/goserver/mser/go/test4.go:17 +0x11e
exit status 2

What's wrong with my file?

360EntSecGroup-Skylar/excelize library reads this file correctly.

cannot using in project with govendor

when my project using govendor to manage golang packages, xlsx2go package cannot compile correctly, the "go:linkname" compile have error, the error belows:
(can you remove the go:linkname in the package?)

liushun.lucien/own_study/vendor/github.com/plandem/xlsx/format/conditional.(*Info).Validate: relocation target github.com/plandem/xlsx/format/conditional/rule.fromRule not defined
liushun.lucien/own_study/vendor/github.com/plandem/xlsx/format/conditional.AddRule.func1: relocation target github.com/plandem/xlsx/format/conditional/rule.fromRule not defined
liushun.lucien/own_study/vendor/github.com/plandem/xlsx.(*conditionals).Add: relocation target github.com/plandem/xlsx/format/conditional.from not defined
liushun.lucien/own_study/vendor/github.com/plandem/xlsx.(*hyperlinks).Add: relocation target github.com/plandem/xlsx/types/hyperlink.from not defined
liushun.lucien/own_study/vendor/github.com/plandem/xlsx.toRichText: relocation target github.com/plandem/xlsx/format/styles.toRichFont not defined
liushun.lucien/own_study/vendor/github.com/plandem/xlsx.(*styleSheet).addDiffStyle: relocation target github.com/plandem/xlsx/format/styles.from not defined
liushun.lucien/own_study/vendor/github.com/plandem/xlsx.(*styleSheet).addStyle: relocation target github.com/plandem/xlsx/format/styles.from not defined

Update Guide, help wanted

It would be cool if someone would help to actualize the guide. Library has decent number of features, but not everything is documented (there are API documentation, tests and examples).

E.g. conditional formatting, as well as, styles are fully implemented, but not documented yet.

Stream write

Hi!

Have u got any examples of stream writing?
Or this lib has only stream read mode

Make `sheetMode` public

I would like to do something like:

var flags xlsx.SheetMode 
if !save {
  flags = xlsx.SheetModeStream
}
...
[perhaps elsewhere...]
...
sheet := xl.Sheet(0, flags)

But:

  • sheetMode can't be referenced
  • nice to have a name for the "default mode" (SheetModeUnknown?) available.

Of course there are other ways to do this, but it would seem a trivial change to the package that would allow more idiomatic code.

The correct way to get sheets based on name.

I'm doing it now in the following way:

for i, v := range spreadsheet.GetSheetNames() {
	if v == name {
		return spreadsheet.Sheet(i)
	}
}
return nil

But I'm not sure it's right in all cases.

ColIterator will cause some conditional format information lost.

package main

import (
	"log"

	"github.com/plandem/xlsx"
)

func main() {
	xl, err := xlsx.Open("test.xlsx")
	if err != nil {
		log.Fatal(err)
	}
	defer xl.Close()

	// NOTE If uncomment the code, some conditional format information will lost.
	for cols := xl.Sheet(0).Cols(); cols.HasNext(); {
		cols.Next()
	}

	//	xl.Save() ERROR: Access is denied.
	xl.SaveAs("out.xlsx")
}

test.xlsx
out.xlsx

sheet corrupted after save

While working on #37, I tried to open a truncated version of an example spreadsheet in "not streaming" mode to make my modifications.

Here is the original sheet:

mfi101119holdingslist_100_noissuer.xlsx

The goal is to lookup matches for the "issuer" column in a database of previous entries and select the best match.

To this end I iterate though the sheet using row = rows.Next() collect some fields to use in a database query, then use

cell := match.Row.Cell(mi.IColIssuer)
// everything output by this diagnostic is reasonble
fmt.Println("I", match.Row.Bounds(), mi.IColIssuer, match.Issuer)
cell.SetText(match.Issuer)

to write the data (match.Issuer is of type string).
Finally I save the data; it doesn't seem to be documented whether to call save before or after sheet.Close() so I tried both ways:

sheet.Close()
xl.SaveAs("./foo.xlsx") // also tried this first
xl.Close()

The resulting file is corrupt:
foo.xlsx

Panic: runtime error: index out of range [1] with length 1

When trying to read the hidden "info" sheet, a panic occurs. I attach the file.

bad.xlsx

panic: runtime error: index out of range [1] with length 1 [recovered]
	panic: runtime error: index out of range [1] with length 1

goroutine 50 [running]:
testing.tRunner.func1.1(0x19ea560, 0xc0003cbfa0)
	/usr/local/Cellar/go/1.15.5/libexec/src/testing/testing.go:1072 +0x30d
testing.tRunner.func1(0xc000001e00)
	/usr/local/Cellar/go/1.15.5/libexec/src/testing/testing.go:1075 +0x41a
panic(0x19ea560, 0xc0003cbfa0)
	/usr/local/Cellar/go/1.15.5/libexec/src/runtime/panic.go:969 +0x1b9
github.com/plandem/xlsx.(*sheetReadWrite).expandOnInit(0xc0000103e0)
	/Users/arzaborskiy/go/pkg/mod/github.com/plandem/[email protected]/sheet_readwrite.go:250 +0x516
github.com/plandem/ooxml.(*PackageFile).LoadIfRequired(0xc000238910, 0xc000515c20)
	/Users/arzaborskiy/go/pkg/mod/github.com/plandem/[email protected]/package_file.go:93 +0x8e
github.com/plandem/xlsx.(*sheetReadWrite).afterOpen(0xc0000103e0)
	/Users/arzaborskiy/go/pkg/mod/github.com/plandem/[email protected]/sheet_readwrite.go:360 +0x5c
github.com/plandem/xlsx.(*Spreadsheet).Sheet(0xc0002381e0, 0x3, 0x0, 0x0, 0x0, 0x0, 0x203000)
	/Users/arzaborskiy/go/pkg/mod/github.com/plandem/[email protected]/spreadsheet.go:106 +0x232
github.com/plandem/xlsx.(*Spreadsheet).SheetByName(0xc0002381e0, 0x1a6de1d, 0x4, 0x0, 0x0, 0x0, 0xc000515db8, 0x100f830)
	/Users/arzaborskiy/go/pkg/mod/github.com/plandem/[email protected]/spreadsheet.go:60 +0xde

if you open the sheet with the option SheetModeIgnoreDimension, then everything is ok

sheet := file.SheetByName(name, xlsx.SheetModeIgnoreDimension)

unnecessary conversion

xlsx/format/font.go:92:57

charset is already FontCharsetType so unnecessary to convert with primitives.FontCharsetType()

func (f *fontOption) Charset(charset FontCharsetType) styleOption {
	return func(s *StyleFormat) {
		if charset >= FontCharsetANSI && charset <= FontCharsetOEM {
			//FIXME: right now it's not possible to encode 'Ansi' charset with 'omitempty'
			s.styleInfo.Font.Charset = primitives.FontCharsetType(charset)
		}
	}
}

Also please check unnecessary conversions:

xlsx/internal/hash/fill.go:33:30

		strconv.FormatFloat(float64(f.Gradient.Degree), 'f', -1, 64),
xlsx/internal/hash/fill.go:34:30:

		strconv.FormatFloat(float64(f.Gradient.Left), 'f', -1, 64),

In stream mode, an exception occurs when get cell's value as string.

package main

import (
	"fmt"

	"github.com/plandem/xlsx"
)

func main() {
	xl, err := xlsx.Open("test.xlsx")
	if err != nil {
		panic(err)
	}
	defer xl.Close()

	sheet := xl.Sheet(0, xlsx.SheetModeStream)
	defer sheet.Close()
	for rows := sheet.Rows(); rows.HasNext(); {
		_, row := rows.Next()
		//		fmt.Println(row.Cell(3).Value())
		fmt.Println(row.Cell(3).String())
	}
}

test.xlsx

Use of fmt.Sprintf unnecessary

Small bug :-)

xlsx/types/hyperlink.go:206:27
escapeLocation() returns a string so no need to use fmt.Sprintf


//ToBookmark sets target to bookmark, that can be named region in xlsx, bookmark of remote file or even site
func (o *hyperlinkOption) ToBookmark(location string) hyperlinkOption {
	return func(i *HyperlinkInfo) {
		if len(location) > 0 {
			if location[0] == '#' {
				location = location[1:]
			}

			//ref only, can be cell or bookmark
			i.hyperlink.Location = fmt.Sprintf("%s", escapeLocation(location))
		}
	}
}

{header:1} facing issue

Argument of type '{ header: number; }' is not assignable to parameter of type 'Sheet2CSVOpts'.
Object literal may only specify known properties, and 'header' does not exist in type 'Sheet2CSVOpts'.

const data = XLSX.utils.sheet_to_csv(ws,{ header: 1 });

Доступ к NewRange

Привет, что если бы была функция которая возвращает Range, как ты на это смотришь?
Если все ок, могу кинуть PR

//Range is a object that provides some functionality for cells inside of range. E.g.: A1:D12
type Range struct {
	//we don't want to pollute Range with bound's public properties
	bounds types.Bounds
	sheet  Sheet
}

//NewRange create and returns Range by bounds [see types.BoundsFromIndexes()] and sheet interface
func NewRange(bounds types.Bounds, sheet Sheet) *Range {
	return &Range{
		bounds,
		sheet,
	}
}

Я тут пишу обертку над твоей либой, было бы удобно объединять ячейки зная только индексы строк и столбцов

Question "sed"-like editing support

I would like to update very large xlsx files in stream mode, setting information in given rows of a sheet as I iterate over it.

I tried updating a stream using the current version. Cell.SetText() panics with:

    not supported in read-only mode
    /Users/shauncutts/src/other/pkg/mod/github.com/plandem/[email protected]/cell.go:130

In fact, Cell.SetInlineText() succeeds; however, the resulting text is not present.

Would this be hard to add?

Update One possibility would be to add an additional sheet in streaming write mode, copy over everything while making modifications, then close and delete the original sheet, and rename the new sheet. (sigh). But looking around I don't see any facilities for copying data from one sheet to another. Would that be a promising approach?

Formula not job

I can't figure out how to insert the formula, it is inserted as text and is not applied
=СЧЁТЗ(G237:G238)

Unable to use vars (type string) as type types.Ref in argument to sheet.Range

Description:

I am still new to go and perhaps this is not an issue but more of a lack of understanding on my part.

However, I am unable to use vars (type string) as type types.Ref in argument to sheet.Range when trying to access range by references in A1notation

Steps to reproduce the issue:

Working code

This current code works well if range references are known and can be written into the script:

package main

import (
  "fmt"
  "strings"

  "github.com/plandem/xlsx"
)

// declare document
const doc string = "./test_files/example_simple.xlsx"

func main() {
  xl, err := xlsx.Open(doc)
  if err != nil {
    panic(err)
  }
  defer xl.Close()

  // Get sheet by 0-based index
  sheet := xl.Sheet(0)

  // // Get range by references
  area := sheet.Range("D10:H13")
  fmt.Println(strings.Join(area.Values(), ","))
}

Broken code

This can allow for changes to the range since the refs are vars but does not work:

package main

import (
  "fmt"
  "strings"

  "github.com/plandem/xlsx"
)

// declare document
const doc string = "./test_files/example_simple.xlsx"

func main() {
  xl, err := xlsx.Open(doc)
  if err != nil {
    panic(err)
  }
  defer xl.Close()

  // Get sheet by 0-based index
  sheet := xl.Sheet(0)

  // // Get range by vars
  var rangeStart string = "D10"
  var rangeEnd string = "H13"
  area := sheet.Range(rangeStart + ":" + rangeEnd)
  fmt.Println(strings.Join(area.Values(), ","))
}

Error from broken code:

.\read-range.go:44:40: cannot use rangeStart + ":" + rangeEnd (type string) as type types.Ref in argument to sheet.Range

Expected results:

It was expected that both the working code and the broken code would return the same results, however they do not.

Debug Info

Output of go version:

go version go1.11.1 windows/amd64

xlsx commit id

529e812

Conditional format may lost

Open a file which has several conditional formats, and then save as a new file. The new file only has the last conditional format, the others conditional formats have been lost.

Benchmark code?

Could you please also upload the code you are using for the benchmark so I can test it on my hardware? Thanks

cannot using in project with govendor

when my project using govendor to manage golang packages, xlsx2go package cannot compile correctly, the "go:linkname" compile have error, the error belows:
(can you remove the go:linkname in the package?)

command-line-arguments

liushun.lucien/own_study/vendor/github.com/plandem/xlsx/format/conditional.(*Info).Validate: relocation target github.com/plandem/xlsx/format/conditional/rule.fromRule not defined
liushun.lucien/own_study/vendor/github.com/plandem/xlsx/format/conditional.AddRule.func1: relocation target github.com/plandem/xlsx/format/conditional/rule.fromRule not defined
liushun.lucien/own_study/vendor/github.com/plandem/xlsx.(*conditionals).Add: relocation target github.com/plandem/xlsx/format/conditional.from not defined
liushun.lucien/own_study/vendor/github.com/plandem/xlsx.(*hyperlinks).Add: relocation target github.com/plandem/xlsx/types/hyperlink.from not defined
liushun.lucien/own_study/vendor/github.com/plandem/xlsx.toRichText: relocation target github.com/plandem/xlsx/format/styles.toRichFont not defined
liushun.lucien/own_study/vendor/github.com/plandem/xlsx.(*styleSheet).addDiffStyle: relocation target github.com/plandem/xlsx/format/styles.from not defined
liushun.lucien/own_study/vendor/github.com/plandem/xlsx.(*styleSheet).addStyle: relocation target github.com/plandem/xlsx/format/styles.from not defined

my projects just like this:

strconv.ParseUint: parsing "-15": invalid syntax

Problem opening xlsx -- is attached.

github.com/plandem/ooxml.(*PackageFile).LoadIfRequired(0xc0000a44b0, 0x0)
	/Users/shauncutts/other/pkg/mod/github.com/plandem/[email protected]/package_file.go:82 +0xbb
github.com/plandem/xlsx.newWorkbook(0x12d4540, 0xc0000c8420, 0xc0000a4280, 0xc0000a4300)
	
[mfi0113_1.xlsx](https://github.com/plandem/xlsx/files/2753561/mfi0113_1.xlsx)
/Users/shauncutts/other/pkg/mod/github.com/plandem/[email protected]/workbook.go:24 +0xe8
github.com/plandem/xlsx.(*Spreadsheet).readSpreadsheet(0xc0000a4280)
	/Users/shauncutts/other/pkg/mod/github.com/plandem/[email protected]/spreadsheet.go:144 +0x363
github.com/plandem/xlsx.newSpreadsheet(0xc00001e2c0, 0xc00001e100, 0xc00001e2c0, 0xc00001e100, 0x0)
	/Users/shauncutts/other/pkg/mod/github.com/plandem/[email protected]/spreadsheet.go:35 +0xc0
github.com/plandem/ooxml.Open(0x12ae040, 0xc00000e0a0, 0x13087f8, 0x14fe0e0, 0x2, 0x1b00000, 0x0)
	/Users/shauncutts/other/pkg/mod/github.com/plandem/[email protected]/package.go:114 +0xd4
github.com/plandem/xlsx.Open(0x12ae040, 0xc00000e0a0, 0xc000014c80, 0xc00000e0a8, 0x1340540)
	/Users/shauncutts/other/pkg/mod/github.com/plandem/[email protected]/xlsx.go:12 +0x59

mfi0113_1.xlsx

Save xlsx file to []bytes or io.Writer

Hi, man, this xlsx libary is very useful for me to read big excel files, but there have a pity the file can only save by fileName, why not provide a method to save as []byte or to io.Writer.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.