worksheet.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package xlsx
  2. import (
  3. "encoding/xml"
  4. )
  5. // xlsxWorksheet directly maps the worksheet element in the namespace
  6. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  7. // currently I have not checked it for completeness - it does as much
  8. // as I need.
  9. type xlsxWorksheet struct {
  10. XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main worksheet"`
  11. Dimension xlsxDimension `xml:"dimension"`
  12. SheetData xlsxSheetData `xml:"sheetData"`
  13. }
  14. // xlsxDimension directly maps the dimension element in the namespace
  15. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  16. // currently I have not checked it for completeness - it does as much
  17. // as I need.
  18. type xlsxDimension struct {
  19. Ref string `xml:"ref,attr"`
  20. }
  21. // xlsxSheetData directly maps the sheetData element in the namespace
  22. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  23. // currently I have not checked it for completeness - it does as much
  24. // as I need.
  25. type xlsxSheetData struct {
  26. XMLName xml.Name `xml:"sheetData"`
  27. Row []xlsxRow `xml:"row"`
  28. }
  29. // xlsxRow directly maps the row element in the namespace
  30. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  31. // currently I have not checked it for completeness - it does as much
  32. // as I need.
  33. type xlsxRow struct {
  34. R int `xml:"r,attr"`
  35. Spans string `xml:"spans,attr,omitempty"`
  36. C []xlsxC `xml:"c"`
  37. }
  38. // xlsxC directly maps the c element in the namespace
  39. // http://schemas.openxmlformats.org/sprceadsheetml/2006/main -
  40. // currently I have not checked it for completeness - it does as much
  41. // as I need.
  42. type xlsxC struct {
  43. R string `xml:"r,attr"` // Cell ID, e.g. A1
  44. S int `xml:"s,attr,omitempty"` // Style reference.
  45. T string `xml:"t,attr"` // Type.
  46. V string `xml:"v"` // Value
  47. }
  48. // get cell
  49. func (sh *Sheet) Cell(row, col int) *Cell {
  50. if len(sh.Rows) > row && sh.Rows[row] != nil && len(sh.Rows[row].Cells) > col {
  51. return sh.Rows[row].Cells[col]
  52. }
  53. return new(Cell)
  54. }