// 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.
182381
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
}
802074
func (f *File) NewSections(names ...string) (err error) {
	for _, name := range names {
		if _, err = f.NewSection(name); err != nil {
			return err
		}
	}
	return nil
}
977993
func (styles *xlsxStyleSheet) newNumFmt(formatCode string) xlsxNumFmt {
	if compareFormatString(formatCode, "general") {
		return xlsxNumFmt{NumFmtId: 0, FormatCode: "general"}
	}
	// built in NumFmts in xmlStyle.go, traverse from the const.
	numFmtId, ok := builtInNumFmtInv[formatCode]
	if ok {
		return xlsxNumFmt{NumFmtId: numFmtId, FormatCode: formatCode}
	}

	// find the exist xlsxNumFmt
	for _, numFmt := range styles.NumFmts.NumFmt {
		if formatCode == numFmt.FormatCode {
			return numFmt
		}
	}

	// The user define NumFmtId. The one less than 164 in built in.
	numFmtId = builtinNumFmtsCount + 1
	styles.Lock()
	defer styles.Unlock()
	for {
		// get a unused NumFmtId
		if _, ok = styles.numFmtRefTable[numFmtId]; ok {
			numFmtId++
		} else {
			styles.addNumFmt(xlsxNumFmt{NumFmtId: numFmtId, FormatCode: formatCode})
			break
		}
	}
	return xlsxNumFmt{NumFmtId: numFmtId, FormatCode: formatCode}
}
884180
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"
	sheetRels := f.workSheetRelsReader(rels)
	if sheetRels == nil {
		sheetRels = &xlsxWorkbookRels{}
	}
	var rID = 1
	var ID bytes.Buffer
	ID.WriteString("rId")
	ID.WriteString(strconv.Itoa(rID))
	ID.Reset()
	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,
	})
	f.WorkSheetRels[rels] = sheetRels
	return rID
}
21718
func NewString(name string) *String {
	v := new(String)
	Publish(name, v)
	return v
}
301222
func NewSet(host *Host, name string) (*Set, error) {
	s := &Set{host, name}
	if _, err := s.host.db.Exec("CREATE TABLE IF NOT EXISTS " + name + " (" + setCol + " " + defaultStringType + ")"); err != nil {
		return nil, err
	}
	if Verbose {
		log.Println("Created table " + name + " in database " + host.dbname)
	}
	return s, nil
}
646136
func (er *expressionRewriter) newFunction(funcName string, retType *types.FieldType, args ...expression.Expression) (expression.Expression, error) {
	if er.disableFoldCounter > 0 {
		return expression.NewFunctionBase(er.ctx, funcName, retType, args...)
	}
	return expression.NewFunction(er.ctx, funcName, retType, args...)
}
425683
func LONewSpreadsheet(desktop *ole.IDispatch) (document *ole.IDispatch) {
	var args = []string{}
	document = oleutil.MustCallMethod(desktop,
		"loadComponentFromURL", "private:factory/scalc", // alternative: private:factory/swriter
		"_blank", 0, args).ToIDispatch()
	return
}
440416
func NewGetStyleSheetTextArgs(styleSheetID StyleSheetID) *GetStyleSheetTextArgs {
	args := new(GetStyleSheetTextArgs)
	args.StyleSheetID = styleSheetID
	return args
}
672297
func NewStatsdTable(cells Cells) Table {
	return Table{
		Cells: cells,
		Columns: []Column{
			{Field: Bucket, Name: "Bucket", Width: max(cells.MaxLen(Bucket)+2, 20)},
			{Field: Type, Name: "Type", Width: 11},
			{Field: Description, Name: "Description", Width: 60},
		},
	}
}
226699
func NewFile() *File {
	return &File{
		Sheet:        make(map[string]*Sheet),
		Sheets:       make([]*Sheet, 0),
		DefinedNames: make([]*xlsxDefinedName, 0),
	}
}
181783
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
}
1004716
func NewAsymmetricSpritesheetFromTexture(tr *TextureResource, spriteRegions []SpriteRegion) *Spritesheet {
	return &Spritesheet{
		texture: tr.Texture,
		width:   tr.Width,
		height:  tr.Height,
		cells:   spriteRegions,
		cache:   make(map[int]Texture),
	}
}
897470
func (parser *Parser) ParseStylesheet() (*css.Stylesheet, error) {
	result := css.NewStylesheet()

	// Parse BOM
	if _, err := parser.parseBOM(); err != nil {
		return result, err
	}

	// Parse list of rules
	rules, err := parser.ParseRules()
	if err != nil {
		return result, err
	}

	result.Rules = rules

	return result, nil
}
287193
func readRowsFromSheet(Worksheet *xlsxWorksheet, file *File, sheet *Sheet, rowLimit int) ([]*Row, []*Col, int, int) {
	var rows []*Row
	var cols []*Col
	var row *Row
	var minCol, maxCol, maxRow, colCount, rowCount int
	var reftable *RefTable
	var err error
	var insertRowIndex, insertColIndex int
	sharedFormulas := map[int]sharedFormula{}

	if len(Worksheet.SheetData.Row) == 0 {
		return nil, nil, 0, 0
	}
	reftable = file.referenceTable
	if len(Worksheet.Dimension.Ref) > 0 && len(strings.Split(Worksheet.Dimension.Ref, cellRangeChar)) == 2 && rowLimit == NoRowLimit {
		minCol, _, maxCol, maxRow, err = getMaxMinFromDimensionRef(Worksheet.Dimension.Ref)
	} else {
		minCol, _, maxCol, maxRow, err = calculateMaxMinFromWorksheet(Worksheet)
	}
	if err != nil {
		panic(err.Error())
	}

	rowCount = maxRow + 1
	colCount = maxCol + 1
	rows = make([]*Row, rowCount)
	cols = make([]*Col, colCount)
	for i := range cols {
		cols[i] = &Col{
			Hidden: false,
		}
	}

	if Worksheet.Cols != nil {
		// Columns can apply to a range, for convenience we expand the
		// ranges out into individual column definitions.
		for _, rawcol := range Worksheet.Cols.Col {
			// Note, below, that sometimes column definitions can
			// exist outside the defined dimensions of the
			// spreadsheet - we deliberately exclude these
			// columns.
			for i := rawcol.Min; i <= rawcol.Max && i <= colCount; i++ {
				col := &Col{
					Min:          rawcol.Min,
					Max:          rawcol.Max,
					Hidden:       rawcol.Hidden,
					Width:        rawcol.Width,
					OutlineLevel: rawcol.OutlineLevel}
				cols[i-1] = col
				if file.styles != nil {
					col.style = file.styles.getStyle(rawcol.Style)
					col.numFmt, col.parsedNumFmt = file.styles.getNumberFormat(rawcol.Style)
				}
			}
		}
	}

	numRows := len(rows)
	for rowIndex := 0; rowIndex < len(Worksheet.SheetData.Row); rowIndex++ {
		rawrow := Worksheet.SheetData.Row[rowIndex]
		// Some spreadsheets will omit blank rows from the
		// stored data
		for rawrow.R > (insertRowIndex + 1) {
			// Put an empty Row into the array
			if insertRowIndex < numRows {
				rows[insertRowIndex] = makeEmptyRow(sheet)
			}
			insertRowIndex++
		}
		// range is not empty and only one range exist
		if len(rawrow.Spans) != 0 && strings.Count(rawrow.Spans, cellRangeChar) == 1 {
			row = makeRowFromSpan(rawrow.Spans, sheet)
		} else {
			row = makeRowFromRaw(rawrow, sheet)
		}

		row.Hidden = rawrow.Hidden
		height, err := strconv.ParseFloat(rawrow.Ht, 64)
		if err == nil {
			row.Height = height
		}
		row.isCustom = rawrow.CustomHeight
		row.OutlineLevel = rawrow.OutlineLevel

		insertColIndex = minCol
		for _, rawcell := range rawrow.C {
			h, v, err := Worksheet.MergeCells.getExtent(rawcell.R)
			if err != nil {
				panic(err.Error())
			}
			x, _, _ := GetCoordsFromCellIDString(rawcell.R)

			// K1000000: Prevent panic when the range specified in the spreadsheet
			//           view exceeds the actual number of columns in the dataset.

			// Some spreadsheets will omit blank cells
			// from the data.
			for x > insertColIndex {
				// Put an empty Cell into the array
				if insertColIndex < len(row.Cells) {
					row.Cells[insertColIndex] = new(Cell)
				}
				insertColIndex++
			}
			cellX := insertColIndex

			if cellX < len(row.Cells) {
				cell := row.Cells[cellX]
				cell.HMerge = h
				cell.VMerge = v
				fillCellData(rawcell, reftable, sharedFormulas, cell)
				if file.styles != nil {
					cell.style = file.styles.getStyle(rawcell.S)
					cell.NumFmt, cell.parsedNumFmt = file.styles.getNumberFormat(rawcell.S)
				}
				cell.date1904 = file.Date1904
				// Cell is considered hidden if the row or the column of this cell is hidden
				cell.Hidden = rawrow.Hidden || (len(cols) > cellX && cols[cellX].Hidden)
				insertColIndex++
			}
		}
		if len(rows) > insertRowIndex {
			rows[insertRowIndex] = row
		}
		insertRowIndex++
	}

	// insert trailing empty rows for the rest of the file
	for ; insertRowIndex < rowCount; insertRowIndex++ {
		rows[insertRowIndex] = makeEmptyRow(sheet)
	}
	return rows, cols, colCount, rowCount
}
738168
func NewScriptFunction(script string) ScriptFunction {
	return ScriptFunction{
		script: script,
		params: make(map[string]interface{}),
	}
}
818215
func (s *Sheet) maybeAddCol(cellCount int) {
	if cellCount > s.MaxCol {
		col := &Col{
			style:     NewStyle(),
			Min:       cellCount,
			Max:       cellCount,
			Hidden:    false,
			Collapsed: false}
		s.Cols = append(s.Cols, col)
		s.MaxCol = cellCount
	}
}