0x4a52466c696e74 1 år sedan
förälder
incheckning
3dcf5aaa96
5 ändrade filer med 56 tillägg och 7 borttagningar
  1. 3 1
      cell_image.go
  2. BIN
      tmp.xlsx
  3. 25 0
      z_image.json
  4. 9 6
      z_source.json
  5. 19 0
      z_test.go

+ 3 - 1
cell_image.go

@@ -27,7 +27,9 @@ func (s *cellImage) UnmarshalJSON(src []byte) (err error) {
 				case "path":
 					err = dec.Decode(&s.path)
 				case "format":
-					err = dec.Decode(&s.format)
+					if err = dec.Decode(&s.format); err != nil {
+						s.format = nil
+					}
 				case "name":
 					err = dec.Decode(&s.name)
 				case "ext":

BIN
tmp.xlsx


+ 25 - 0
z_image.json

@@ -0,0 +1,25 @@
+    [
+        {
+            "name": "basket",
+            "images": [ 
+                {
+                "x": 0,
+                "y": 0,
+                "format": { 
+                    "print_obj": true,
+                    "positioning": "absolute",
+                    "autofit": false,
+                    "lock_aspect_ratio": true,
+                    "x_scale": 1,
+                    "y_scale": 1,
+                    "x_offset": 1,
+                    "y_offset": 1
+
+                },
+                "path": "image_copy",
+                "ext": ".jpg",
+                "name": "11111"
+                }
+            ]
+        }
+    ]

+ 9 - 6
z_source.json

@@ -3,15 +3,18 @@
             "name": "basket",
             "images": [ 
                 {
-                "x": 2,
-                "y": 2,
+                "x": 0,
+                "y": 0,
                 "format": { 
-                    "x_scale": 0.5, 
-                    "y_scale": 1,
-                    "lock_aspect_ratio": true,
+                    "print_obj": true,
                     "positioning": "absolute",
                     "autofit": false,
-                    "print_obj": true
+                    "lock_aspect_ratio": true,
+                    "x_scale": 1,
+                    "y_scale": 1,
+                    "x_offset": 1,
+                    "y_offset": 1
+
                 },
                 "path": "image_copy",
                 "ext": ".jpg",

+ 19 - 0
z_test.go

@@ -26,6 +26,25 @@ func TestXVDoc(t *testing.T) {
 	}
 }
 
+func TestImage(t *testing.T) {
+	if src, err := ioutil.ReadFile("z_image.json"); err == nil {
+		if docs, err := FromJSON(src); err == nil {
+			log.Println("!!!!!!!", len(docs), docs)
+			log.Println("=============================")
+			if exp, err := Export("xlsx", docs); err == nil {
+				ioutil.WriteFile("tmp.xlsx", exp, 0660)
+			} else {
+				log.Println(err)
+			}
+
+		} else {
+			t.Error(err)
+		}
+	} else {
+		t.Error(err)
+	}
+}
+
 func TestXLSXImport(t *testing.T) {
 	sheets, err := ImportXLSXFromFile("tmp.xlsx")
 	fmt.Println(sheets, "|", err)