Explorar o código

add Selected variable for sheet(preventing auto multi-tab selected
workbook.Sheets.Sheet's relationship:id -> r:id for resolving error when
reading excel at SAS

blackss2 %!s(int64=10) %!d(string=hai) anos
pai
achega
2972894555
Modificáronse 4 ficheiros con 9 adicións e 2 borrados
  1. 6 0
      file.go
  2. 1 0
      sheet.go
  3. 1 1
      xmlWorkbook.go
  4. 1 1
      xmlWorksheet.go

+ 6 - 0
file.go

@@ -113,6 +113,9 @@ func (f *File) Write(writer io.Writer) (err error) {
 // Add a new Sheet, with the provided name, to a File
 func (f *File) AddSheet(sheetName string) (sheet *Sheet) {
 	sheet = &Sheet{Name: sheetName, File: f}
+	if len(f.Sheets) == 0 {
+		sheet.Selected = true
+	}
 	f.Sheet[sheetName] = sheet
 	f.Sheets = append(f.Sheets, sheet)
 	return sheet
@@ -177,6 +180,9 @@ func (f *File) MarshallParts() (map[string]string, error) {
 	f.styles.reset()
 	for _, sheet := range f.Sheets {
 		xSheet := sheet.makeXLSXSheet(refTable, f.styles)
+		if sheet.Selected {
+			xSheet.SheetViews.SheetView[0].TabSelected = true
+		}
 		rId := fmt.Sprintf("rId%d", sheetIndex)
 		sheetId := strconv.Itoa(sheetIndex)
 		sheetPath := fmt.Sprintf("worksheets/sheet%d.xml", sheetIndex)

+ 1 - 0
sheet.go

@@ -15,6 +15,7 @@ type Sheet struct {
 	MaxRow      int
 	MaxCol      int
 	Hidden      bool
+	Selected    bool
 	SheetViews  []SheetView
 	SheetFormat SheetFormat
 }

+ 1 - 1
xmlWorkbook.go

@@ -114,7 +114,7 @@ type xlsxSheets struct {
 type xlsxSheet struct {
 	Name    string `xml:"name,attr,omitempty"`
 	SheetId string `xml:"sheetId,attr,omitempty"`
-	Id      string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
+	Id      string `xml:"r:id,attr,omitempty"`
 	State   string `xml:"state,attr,omitempty"`
 }
 

+ 1 - 1
xmlWorksheet.go

@@ -282,7 +282,7 @@ func newXlsxWorksheet() (worksheet *xlsxWorksheet) {
 		ShowOutlineSymbols:      true,
 		ShowRowColHeaders:       true,
 		ShowZeros:               true,
-		TabSelected:             true,
+		TabSelected:             false,
 		TopLeftCell:             "A1",
 		View:                    "normal",
 		WindowProtection:        false,