On Tue, Mar 14, 2023 at 6:27 PM Frank Jüdes <jued...@gmail.com> wrote:
>
> i still somewhat new with Go and need a little tutoring: I have to create 
> Excel files, using the excelize package and wrote a little function to store 
> data from a map[string]int64 into a column within the worksheet:
>
> // 
> -------------------------------------------------------------------------------------------------
> // Store a slice of int64 data items into the cells of a column
> // 
> -------------------------------------------------------------------------------------------------
> func SetColumnValuesInt64(xf *excelize.File,
>       p_SheetName string,
>       p_StartRow int,
>       p_Column rune,
>       p_CellStyle *excelize.Style,
>       p_Keys *UTL_StringSlice.T_StringSlice,
>       p_Values *map[string]int64) {
>    Row := p_StartRow
>    StyleID,_ := xf.NewStyle(p_CellStyle)
>    for _,Key := range(*p_Keys) {
>      CellAddress := fmt.Sprintf("%c%d",p_Column,Row)
>      xf.SetCellValue(p_SheetName,CellAddress,(*p_Values)[Key])
>      xf.SetCellStyle(p_SheetName,CellAddress,CellAddress,StyleID)
>     Row++
>    } // END for
> } // END SetColumnValuesInt64
>
> Basically the function iterates through a slice of strings, containing the 
> key-values for the data-map and then calls the SetCellValue function from the 
> excelize package to store the number into the cell.
> Now i have another set of data, stored into a map[string]float64 …
> So i duplicated the above function, just replacing the red line with
>       p_Values *map[string]float64) {
>
> Basically it is the same code, just the parameter-type is different. I looked 
> into the definition of the function SetCellValue  and saw that it is using 
> the empty interface as parameter for the value, so i tried to define my 
> function with
>       p_Values *map[string]interface{}) {
>
> The function compiles fine, but if i try to use it with a *map[string]int64 
> as a parameter, the compiler objectst with the message »cannot use Amounts 
> (variable of type *map[string]int64) as type *map[string]interface{} in 
> argument to ExcelFormats.SetColumnValues«
>
> Can somebody please give me hint what i am doing wrong?

First I'll note that it's quite unusual to use a pointer to a map.
Maps are reference types.  If you pass a map to a function, and that
function adds values to the map, the caller will also see the new map
entries.

That said, the error message seems clear enough: a function that
expects a pointer to map[string]any can't take an argument that is a
pointer to map[string]int64.  The types any and int64 are different
types.  You can't interchange them.  See
https://go.dev/doc/faq#covariant_types for a related issue.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcVnv5VE%3DF-Hdd7vMPUzQHqUDJNPtD_SDK2TSL3q-hcDcg%40mail.gmail.com.

Reply via email to