Home > other >  CoInitialize Error can't after setting the thread pattern changes them. COM initialization
CoInitialize Error can't after setting the thread pattern changes them. COM initialization

Time:11-03

Func init () {

FMT. Println ("===init==")

//err:=ole. CoInitializeEx (0, ole. COINIT_MULTITHREADED)

Err:=ole. CoInitializeEx (0, ole COINIT_APARTMENTTHREADED | ole. COINIT_SPEED_OVER_MEMORY)
//err:=ole CoInitialize (0)
//defer ole. CoUninitialize ()
if err ! Nil={
CoInitialize FMT. Println (" Error ", err)
//panic (err)
}




}


Func (fileS * FileScanner) SaveExcel (filePath string, cityId int) (path [] CityExcel, err error) {
FilePath=getCurrentDirectory () + "/" + filePath
File07:=filePath + ". XLSX "
FMT. Println (" 333333333 ", file07)
FileS. Xlsx03Toxls07 (file07 filePath)
FMT. Println (file07)
FMT. Println (filePath)

W, err:=XLSX OpenFile (file07)
if err ! Nil={
FMT. Println (" 23111111111111 ", err)
}

Sheet:=baron heets [0]
SHT:=make ([] Ticket, 0)

If sheet MaxRow!={
1For I, the row:=range sheet. Rows {
If I & gt; 0 {
Ticket: ticket={}
Ticket. CreatedAt=time. Now (). The Format (" the 2006-01-02 15:04:05 ")
Ticket. CityId=CityId
For k, cell:=range row. Cells {

If k=={
2Ticket. ConsumerId=cell. The Value
}
If k=={
1Ticket. Certificate=cell. The Value
}
If k==0 {
Ticket. The Name=cell. The Value
}
If k==6 {
Ticket. The Date=cell. The Value
}
If k==7 {
Ticket. Time=cell. The Value
}
If k==4 {
Ticket. Departure=cell. The Value
}
If k==5 {
Ticket. The Destination=cell. The Value
}

If k=3={
Ticket. TrainNum=cell. The Value
}
}
If the ticket ConsumerId! {
=""Ok, err:=ticket. AddTicket ()
if err ! Nil={
Return nil, err
}
FMT. Println (ok, "okokokok# # # # # # # # # # # # # # # # # #")
//time increment returns
If ok {
SHT=append (SHT, ticket)
}
}
}
}
}
Path, err=fileS. CreateFtpPath (SHT)
FMT. Println (" shshshshshshsahsh!!!!!!!!! ", SHT)
Return path, err
}


Func (fileS * FileScanner) xlsx03Toxls07 (path07, path03 string) {
WordApplication, err:=oleutil. CreateObject (" excel. Application ")

WordAppDispatch, err:=wordApplication. QueryInterface (ole) IID_IDispatch)

WorkBookDis=oleutil. MustGetProperty (wordAppDispatch, "WorkBooks"). The ToIDispatch ()

Defer wordApplication. Release ()
Path07=strings. The Replace (path07, "/", "\ ", 1)
FMT. Println (" path03 before, "path03)
Path03=strings. The Replace (path03, "/", "\ ", 1)
FMT. Println (path07, "path07")
FMT. Println (" path03: "path03, workBookDis)
FMT. Println (workBookDis, "workwork")

The document, err:=oleutil. CallMethod (workBookDis, "Open", path03)
if err ! Nil={
FMT. Println (" 799999 ", err)
}
FMT. Println (document and "document")
FMT. Println (" open, err: "err)

DisDis:=document. ToIDispatch ()
FMT. Println (disDis, "disDis")

//2007 version XLSX 2003 XLS value: 56
//2003 version XLS 2007 XLSX value: 51
The result, err:=oleutil. CallMethod (disDis, "SaveAs" path07, 51)
if err ! Nil={
FMT. Println (" CallMethod faild: ", result, err)
}

Defer oleutil. MustCallMethod (disDis, "Close", false)
}





Could you tell me how to modify it, I wanted to put the XLS file upload interface into XLSX and then to read the stored, but always initialization error and empty address pointer
  • Related