Excelに図形を挿入後、起点の座標を変更したい

以下のWebページを参照しました。

shapeを追加後、起点の座標を変更したいのですが、可能ですか?
また、その場合のサンプルコードをいただきたいです。

@kenable811,

図形の座標を取得する方法と、一部の座標を更新して最終的なワークブックに保存する方法については、次のサンプル コードを参照してください。

Workbook workbook = new Workbook();

// Access first worksheet from the collection
Worksheet sheet = workbook.getWorksheets().get(0);

// Add the line arrow to the worksheet
com.aspose.cells.Shape sh = sheet.getShapes().addShape(MsoDrawingType.LINE, 2, 0, 2, 0, 100, 300);//method 1

//add a arrow at the line begin
sh.getLine().setBeginArrowheadStyle(MsoArrowheadStyle.ARROW);//arrow type
sh.getLine().setBeginArrowheadWidth(MsoArrowheadWidth.WIDE);//arrow width
sh.getLine().setBeginArrowheadLength(MsoArrowheadLength.SHORT);//arrow length

//add a arrow at the line end
sh.getLine().setEndArrowheadStyle(MsoArrowheadStyle.ARROW_OPEN);//arrow type
sh.getLine().setEndArrowheadWidth(MsoArrowheadWidth.NARROW);//arrow width
sh.getLine().setEndArrowheadLength(MsoArrowheadLength.LONG);//arrow length

int upperLeftRow, top, upperLeftColumn, left, height, width;
upperLeftRow = sh.getUpperLeftRow();
top = sh.getTop();
upperLeftColumn = sh.getUpperLeftColumn();
left = sh.getLeft();
height = sh.getHeight();
width = sh.getWidth();

System.out.println("Upper Left Row:" + upperLeftRow + ", Top:" + top + ", UpperLeftColumn:" + upperLeftColumn + ", Left:" + left + ", Height:" + height + ", Width:" + width);

//Save the file.
workbook.save("f:\\files\\sample2.xlsx", SaveFormat.XLSX);

//update coordinates.
sh.setUpperLeftRow(3);
sh.setUpperLeftColumn(3);

Save another file.
workbook.save("f:\\files\\sample3.xlsx", SaveFormat.XLSX);

これが少し役立つことを願っています。

files1.zip (13.7 KB)

ありがとうございます。
私が希望している座標変更と少し異なるかもしれません。

添付ファイルにやりたいことの状態を保存していますので
ご確認いただけますでしょうか?
sample2_add.zip (7.1 KB)

線を挿入して、×印のような形を作りたいと思っています。

また、別件ですが、線矢印を挿入した時に、X方向に180度回転することが可能
ですか?これも以下に添付ファイルを送信しますのでご確認ください。
Book1.zip (14.1 KB)

@kenable811
次のサンプルコードを使用して、2つのニーズを実現することができます。添付ファイルを確認してください。java_out.zip (7.9 KB)

サンプルコードは次の通りです:

Workbook workbook = new Workbook();

// Access first worksheet from the collection
Worksheet sheet = workbook.getWorksheets().get(0);

// Add the line arrow to the worksheet
Shape line1 = sheet.getShapes().addShape(MsoDrawingType.LINE, 4, 0, 4, 0, 100, 300);//method 1

//add a arrow at the line begin
line1.getLine().setBeginArrowheadStyle(MsoArrowheadStyle.ARROW_OPEN);//arrow type
line1.getLine().setBeginArrowheadWidth(MsoArrowheadWidth.NARROW);//arrow width
line1.getLine().setBeginArrowheadLength(MsoArrowheadLength.LONG);//arrow length

//add a arrow at the line end
line1.getLine().setEndArrowheadStyle(MsoArrowheadStyle.ARROW);//arrow type
line1.getLine().setEndArrowheadWidth(MsoArrowheadWidth.WIDE);//arrow width
line1.getLine().setEndArrowheadLength(MsoArrowheadLength.SHORT);//arrow length


// Add the line arrow to the worksheet
Shape line2 = sheet.getShapes().addShape(MsoDrawingType.LINE, 4, 0, 4, 0, 100, 300);//method 1

//add a arrow at the line begin
line2.getLine().setBeginArrowheadStyle(MsoArrowheadStyle.ARROW_OPEN);//arrow type
line2.getLine().setBeginArrowheadWidth(MsoArrowheadWidth.NARROW);//arrow width
line2.getLine().setBeginArrowheadLength(MsoArrowheadLength.LONG);//arrow length

//add a arrow at the line end
line2.getLine().setEndArrowheadStyle(MsoArrowheadStyle.ARROW);//arrow type
line2.getLine().setEndArrowheadWidth(MsoArrowheadWidth.WIDE);//arrow width
line2.getLine().setEndArrowheadLength(MsoArrowheadLength.SHORT);//arrow length

line2.setRotationAngle(135);


// Add the line arrow to the worksheet
Shape line3 = sheet.getShapes().addShape(MsoDrawingType.LINE, 10, 0, 10, 0, 30, 50);//method 1

//add a arrow at the line begin
line3.getLine().setBeginArrowheadStyle(MsoArrowheadStyle.ARROW);//arrow type
line3.getLine().setBeginArrowheadWidth(MsoArrowheadWidth.MEDIUM);//arrow width
line3.getLine().setBeginArrowheadLength(MsoArrowheadLength.SHORT);//arrow length

line3.getLine().setWeight(4.5);
line3.setWidthPt(7.5);
line3.setHeightPt(13.5);

// Add the line arrow to the worksheet
Shape line4 = sheet.getShapes().addShape(MsoDrawingType.LINE, 12, 0, 10, 0, 30, 50);//method 1

//add a arrow at the line begin
line4.getLine().setBeginArrowheadStyle(MsoArrowheadStyle.ARROW);//arrow type
line4.getLine().setBeginArrowheadWidth(MsoArrowheadWidth.MEDIUM);//arrow width
line4.getLine().setBeginArrowheadLength(MsoArrowheadLength.SHORT);//arrow length

line4.getLine().setWeight(4.5);
line4.setRotationAngle(90);
line4.setWidthPt(7.5);
line4.setHeightPt(13.5);

//Save the file.
workbook.save(filePath + "java_out.xlsx", SaveFormat.XLSX);

ご対応ありがとうございます。

実装するコードがC#ですが、workbook.getWorksheets()でworkbookにはgetWorksheetsの定義が存在しないとエラーになります。
getWorksheets()のメソッドは何の参照が必要なのでしょうか?

@kenable811
C#サンプルコードと添付ファイルを参照してください。net_out.zip (7.8 KB)

サンプルコードは次の通りです:

Workbook workbook = new Workbook();

// Access first worksheet from the collection
Worksheet sheet = workbook.Worksheets[0];

// Add the line arrow to the worksheet
Shape line1 = sheet.Shapes.AddShape(MsoDrawingType.Line, 4, 0, 4, 0, 100, 300);//method 1

//add a arrow at the line begin
line1.Line.BeginArrowheadStyle = MsoArrowheadStyle.ArrowOpen;//arrow type
line1.Line.BeginArrowheadWidth = MsoArrowheadWidth.Narrow;//arrow width
line1.Line.BeginArrowheadLength = MsoArrowheadLength.Long;//arrow length

//add a arrow at the line end
line1.Line.EndArrowheadStyle = MsoArrowheadStyle.Arrow;//arrow type
line1.Line.EndArrowheadWidth = MsoArrowheadWidth.Wide;//arrow width
line1.Line.EndArrowheadLength = MsoArrowheadLength.Short;//arrow length


// Add the line arrow to the worksheet
Shape line2 = sheet.Shapes.AddShape(MsoDrawingType.Line, 4, 0, 4, 0, 100, 300);//method 1

//add a arrow at the line begin
line2.Line.BeginArrowheadStyle = MsoArrowheadStyle.ArrowOpen;//arrow type
line2.Line.BeginArrowheadWidth = MsoArrowheadWidth.Narrow;//arrow width
line2.Line.BeginArrowheadLength = MsoArrowheadLength.Long;//arrow length

//add a arrow at the line end
line2.Line.EndArrowheadStyle = MsoArrowheadStyle.Arrow;//arrow type
line2.Line.EndArrowheadWidth = MsoArrowheadWidth.Wide;//arrow width
line2.Line.EndArrowheadLength = MsoArrowheadLength.Short;//arrow length

line2.RotationAngle = 135;


// Add the line arrow to the worksheet
Shape line3 = sheet.Shapes.AddShape(MsoDrawingType.Line, 10, 0, 10, 0, 30, 50);//method 1

//add a arrow at the line begin
line3.Line.BeginArrowheadStyle = MsoArrowheadStyle.Arrow;//arrow type
line3.Line.BeginArrowheadWidth = MsoArrowheadWidth.Medium;//arrow width
line3.Line.BeginArrowheadLength = MsoArrowheadLength.Short;//arrow length

line3.Line.Weight = 4.5;
line3.WidthPt = 7.5;
line3.HeightPt = 13.5;

// Add the line arrow to the worksheet
Shape line4 = sheet.Shapes.AddShape(MsoDrawingType.Line, 12, 0, 10, 0, 30, 50);//method 1

//add a arrow at the line begin
line4.Line.BeginArrowheadStyle = MsoArrowheadStyle.Arrow;//arrow type
line4.Line.BeginArrowheadWidth = MsoArrowheadWidth.Medium;//arrow width
line4.Line.BeginArrowheadLength = MsoArrowheadLength.Short;//arrow length

line4.Line.Weight = 4.5;
line4.RotationAngle = 90;
line4.WidthPt = 7.5;
line4.HeightPt = 13.5;

//Save the file.
workbook.Save(filePath + "net_out.xlsx", SaveFormat.Xlsx);

少し希望と異なるかもしれません。
以下のファイルを添付しました。
sample.zip (14.3 KB)

sample2.xlsx はsample1.xlsx の図形をX方向に180度回転したものになります。
これを実現するには、上記で教えていただいたサンプルコードでは実現できないと思いますが、
いかがでしょうか?

ご確認お願いします。

@kenable811
sample 1.xlsxの線が180度回転すると、sample 2.xlsxの線は得られません。画像をご覧ください。result.png (93.8 KB)

理解しました。

回転する項目が異なる為、以下に画像を添付します。
スクリーンショット 2024-01-18 155233.png (20.2 KB)

これを実現する為には、前回いただいたサンプルコードで実現はできますか?

@kenable811
次のコードを使用してX軸の回転を設定できます。しかし、現在の設定で保存が完了すると、結果ファイルがクラッシュする問題が発生します。

Workbook workbook = new Workbook(filePath + "sample1.xlsx");

// Access first worksheet from the collection
Worksheet sheet = workbook.Worksheets[0];

Shape line1 = sheet.Shapes[0];
line1.ThreeDFormat.RotationX = 180;

//Save the file.
workbook.Save(filePath + "net_out.xlsx", SaveFormat.Xlsx);

内部問題追跡システムで次の新しいチケットを開き、Free Support Policies に記載されている条件に従って修正を提供しています。

質問番号:CELLSNET-55010

ご対応ありがとうございます。
希望通りの処理ができましたが、修復対象のブックとなりました。

どう修正したらこの問題が解決されるか
ここの問合せでサンプルコードなどを提示いただけますでしょうか?

@kenable811,

はい、前の返信でお伝えしたように、上記のコードを使用すると保存プロセスは完了しますが、結果の Excel ファイルを MS Excel で開くとクラッシュします。 ID「CELLSNET-55010」のチケットはデータベース内ですでに開かれています。 すぐに調査させていただきます。

問題が解決されるか、その他の更新があった場合は、ここでお知らせします。

@kenable811
あなたの問題 (CELLSNET-55010) は解決され、修正された機能はバージョン 24.2 でリリースされる予定です。

ご対応ありがとうございます。
バージョン 24.2のリリースはいつを予定していますか?

@kenable811
この修正程序は2024年2月上半月発布予定の発布版(Aspose.Cells v24.2)に含まれる。バージョンがリリースされたら、すぐにお知らせします。

1 Like

@kenable811,

リリースは準備ができ次第公開されるため、正確なリリース日はお知らせできません。 次のバージョン (Aspose.Cells v24.2) が来週リリースされることを願っています。

1 Like

The issues you have found earlier (filed as CELLSNET-55010) have been fixed in this update. This message was posted using Bugs notification tool by johnson.shi