mirror of
https://github.com/Dvorinka/PPve.git
synced 2026-06-05 04:52:58 +00:00
Add files via upload
This commit is contained in:
+18
-30
@@ -201,7 +201,6 @@ func parseExcelFile(filename string) ([]Contact, error) {
|
|||||||
|
|
||||||
func parseTable(f *excelize.File, sheetName, startCol, endCol string) []Contact {
|
func parseTable(f *excelize.File, sheetName, startCol, endCol string) []Contact {
|
||||||
var contacts []Contact
|
var contacts []Contact
|
||||||
var currentContact *Contact
|
|
||||||
|
|
||||||
// Get all rows in the sheet
|
// Get all rows in the sheet
|
||||||
rows, err := f.GetRows(sheetName)
|
rows, err := f.GetRows(sheetName)
|
||||||
@@ -220,6 +219,7 @@ func parseTable(f *excelize.File, sheetName, startCol, endCol string) []Contact
|
|||||||
// Column indices
|
// Column indices
|
||||||
const (
|
const (
|
||||||
nameCol = 0
|
nameCol = 0
|
||||||
|
positionCol = 1
|
||||||
phoneCol = 2
|
phoneCol = 2
|
||||||
servicePhoneCol = 3
|
servicePhoneCol = 3
|
||||||
mobileKlapkaCol = 4
|
mobileKlapkaCol = 4
|
||||||
@@ -238,44 +238,32 @@ func parseTable(f *excelize.File, sheetName, startCol, endCol string) []Contact
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for special formatting rows (like "*02(xx)")
|
contact := Contact{
|
||||||
if len(row) > 1 && strings.Contains(row[1], "*") {
|
Name: strings.TrimSpace(row[nameCol]),
|
||||||
continue
|
Position: safeGet(row, positionCol, ""),
|
||||||
|
Phone: formatPhoneNumber(safeGet(row, phoneCol, "")),
|
||||||
|
ServicePhone: formatPhoneNumber(safeGet(row, servicePhoneCol, "")),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get values from columns (new structure: name, position, phone, service phone, mobile)
|
// Check for mobile klapka if exists
|
||||||
name := strings.TrimSpace(row[0])
|
if len(row) > mobileKlapkaCol && row[mobileKlapkaCol] != "" {
|
||||||
position := strings.TrimSpace(row[1])
|
contact.ServicePhone = formatPhoneNumber(row[mobileKlapkaCol])
|
||||||
phone := strings.TrimSpace(row[2])
|
|
||||||
servicePhone := strings.TrimSpace(row[3])
|
|
||||||
mobileKlapka := ""
|
|
||||||
if len(row) > 4 {
|
|
||||||
mobileKlapka = strings.TrimSpace(row[4])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean phone numbers
|
contacts = append(contacts, contact)
|
||||||
phone = cleanPhoneNumber(phone)
|
|
||||||
servicePhone = cleanPhoneNumber(servicePhone)
|
|
||||||
|
|
||||||
// If we have a name, create new contact
|
|
||||||
if name != "" && !strings.Contains(name, "(") {
|
|
||||||
currentContact = &Contact{
|
|
||||||
Name: name,
|
|
||||||
Position: position,
|
|
||||||
Phone: phone,
|
|
||||||
ServicePhone: servicePhone,
|
|
||||||
}
|
|
||||||
if mobileKlapka != "" {
|
|
||||||
currentContact.Phone += " " + mobileKlapka
|
|
||||||
}
|
|
||||||
contacts = append(contacts, *currentContact)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return contacts
|
return contacts
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanPhoneNumber(phone string) string {
|
func safeGet(row []string, index int, defaultValue string) string {
|
||||||
|
if index < len(row) {
|
||||||
|
return row[index]
|
||||||
|
}
|
||||||
|
return defaultValue
|
||||||
|
}
|
||||||
|
|
||||||
|
func formatPhoneNumber(phone string) string {
|
||||||
if phone == "" {
|
if phone == "" {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user