Skip to content

Commit 012996b

Browse files
committed
Fixed a bug that an error occurs when inserting into a cell with a link destination
1 parent ada2b32 commit 012996b

2 files changed

Lines changed: 101 additions & 78 deletions

File tree

ImageInserter/Ribbon_imageInserter.Designer.cs

Lines changed: 69 additions & 69 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ImageInserter/Ribbon_imageInserter.cs

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,17 @@ await System.Threading.Tasks.Task.Run(() =>
231231
waitDialogDisplay(waitDlg, count, countMax);
232232

233233
// Processing
234-
pasteImage(sheet, cell, getImagePathFromHyperlink(cell));
234+
string imagePath = getImagePathFromCell(cell);
235+
if (imagePath == null)
236+
{
237+
imagePath = getImagePathFromHyperlink(cell);
238+
}
239+
240+
// Check params
241+
if (imagePath != null)
242+
{
243+
pasteImage(sheet, cell, imagePath);
244+
}
235245

236246
count++;
237247
}
@@ -289,7 +299,12 @@ await System.Threading.Tasks.Task.Run(() =>
289299

290300
// Processing
291301
cell = (count == 1) ? cell.Offset[0, 0] : cell.Offset[offsetCol, offsetRow];
292-
pasteImage(sheet, cell, imagePath);
302+
303+
// Check params
304+
if (imagePath != null)
305+
{
306+
pasteImage(sheet, cell, imagePath);
307+
}
293308

294309
count++;
295310
}
@@ -527,11 +542,6 @@ private string preloadImage(ref string imagePath, ref float imageW, ref float im
527542

528543
private void pasteImage(Excel.Worksheet sheet, Excel.Range cell, string imageOrgPath)
529544
{
530-
if (checkImagePath(imageOrgPath) == false)
531-
{
532-
return;
533-
}
534-
535545
// Get UI params
536546
bool pasteCell = false;
537547
bool pasteMemo = false;
@@ -777,13 +787,26 @@ private void pasteImageOnMemo(Excel.Worksheet sheet, Excel.Range cell, string wr
777787
cell.Comment.Shape.Height = shapeH;
778788
}
779789

790+
private string getImagePathFromCell(Excel.Range cell)
791+
{
792+
string imagePath = null;
793+
if (checkImagePath(cell.Text))
794+
{
795+
imagePath = cell.Text;
796+
}
797+
return imagePath;
798+
}
799+
780800
private string getImagePathFromHyperlink(Excel.Range cell)
781801
{
782802
string imagePath = null;
783803
foreach (Excel.Hyperlink link in cell.Hyperlinks)
784804
{
785-
imagePath = link.Address;
786-
break;
805+
if (checkImagePath(link.Address))
806+
{
807+
imagePath = link.Address;
808+
break;
809+
}
787810
}
788811
return imagePath;
789812
}

0 commit comments

Comments
 (0)