Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent Comment Box Shape #1707

Closed
here-bossnanda opened this issue Nov 1, 2023 · 8 comments
Closed

Inconsistent Comment Box Shape #1707

here-bossnanda opened this issue Nov 1, 2023 · 8 comments
Labels
needs more info This issue can't reproduce, need more info

Comments

@here-bossnanda
Copy link

here-bossnanda commented Nov 1, 2023

Description:

When using the excelize library to add comments to cells in an Excel file, I'm observing inconsistent rendering of the comment boxes. Specifically:

For some cells, even with short comment text, the comment is rendered as an arrow-shaped callout.
For other cells, with longer comment text, the comment appears as the expected rectangle shape.
This behavior is inconsistent and seems to be unrelated to the actual length of the comment text. For instance, comments in column D with a longer text are rendered as arrow-shaped, while comments in the "ID Subcategory" column with shorter text are rendered as rectangles.

Screenshot 2023-11-01 at 17 38 51

Code Sample:

xlsx.AddComment(sheetName, excelize.Comment{
		Cell:   cellCoordinates,
		Author: "System",
		Text:   errorText,
		Paragraph: []excelize.RichTextRun{
			{Text: "System: ", Font: &excelize.Font{Bold: true}},
			{Text: errorText},
		},
	})

Expected Behavior:

All comment boxes, regardless of text length, should render consistently, preferably as rectangles.

Actual Behavior:

Comment boxes render inconsistently between arrow-shaped callouts and rectangles, seemingly unrelated to the actual comment text length.

Additional Information:

I've tested the generated file in ms excel version 16.78.3 , and the issue persists.

I'd appreciate any insights or fixes for this issue. Thanks!

@here-bossnanda here-bossnanda changed the title Inconsistent Comment Box Shape in Excel Inconsistent Comment Box Shape Nov 1, 2023
@xuri
Copy link
Member

xuri commented Nov 1, 2023

Thanks for your issue. Which version of the Excelize library are you using? Could you show us a complete, standalone example program or reproducible demo? If you open an existing workbook, please provide the file attachment without confidential info.

@xuri xuri added the needs more info This issue can't reproduce, need more info label Nov 1, 2023
@here-bossnanda
Copy link
Author

here-bossnanda commented Nov 1, 2023

Excelize Version: "github.com/xuri/excelize/v2"

Standalone Example Program:

package main

import (
	"fmt"
	"github.com/xuri/excelize/v2"
)

func main() {
	xlsx, err := excelize.OpenFile(LocationFile)
	if err != nil {
		fmt.Println("Failed to open the file:", err)
	}
	
	sheetName := "Sheet1"

	// Add data and comments
	xlsx.SetCellValue(sheetName, "A1", "ID Subkategori")
	xlsx.SetCellValue(sheetName, "C1", "Kode Paket")
	errorText := "Example error message for demonstration."

	xlsx.AddComment(sheetName, excelize.Comment{
		Cell: "A1",
		Author: "System",
		Text:   errorText,
		Paragraph: []excelize.RichTextRun{
			{Text: "System: ", Font: &excelize.Font{Bold: true}},
			{Text: errorText},
		},
	})

	xlsx.AddComment(sheetName, excelize.Comment{
		Cell: "D1",
		Author: "System",
		Text:   errorText,
		Paragraph: []excelize.RichTextRun{
			{Text: "System: ", Font: &excelize.Font{Bold: true}},
			{Text: errorText},
		},
	})

	// Save the file
	err := xlsx.SaveAs("SampleWorkbook.xlsx")
	if err != nil {
		fmt.Println("Failed to save the file:", err)
	}
}

This standalone example utilizes an existing Excel workbook from a local directory with two cells containing comments. As outlined in the issue. The comment in column D might appear arrow-shaped, while the comment in the "ID Subkategori" column appears rectangle-shaped.

Existing Workbook:
00001_example.xlsx

I've attached a sample Excel file for your reference.

@here-bossnanda
Copy link
Author

here-bossnanda commented Nov 1, 2023

Previously, I was using the package "github.com/360EntSecGroup-Skylar/excelize", and the Comment Box Shape was working fine. However, since that package didn't support deleting comments, I searched online and found a solution by using the package "github.com/xuri/excelize/v2", which has a feature to delete comments. However, I encountered this issue with it.

@xuri
Copy link
Member

xuri commented Nov 2, 2023

Which version of the Excelize library are you using? There are multiple released versions in v2. The comments on cells B1 and C1 in your attachment were not created by this library, right? In your code, the sheet name "Sheet1" doesn't exist in the workbook "00001_example.xlsx", so the comment will not created on cells A1 and D1. If you receive the error returned by the AddComment function, you will get the error message. If you change the sheet name to "Paket Belajar", the comments in the rectangle shape box will be added as expected. I have tested with the lasted version and master branch code, and it works well.

@ghost
Copy link

ghost commented Nov 3, 2023

The version is v2.8.0, I have the same project with the reporter. Thank you very much.

@xuri
Copy link
Member

xuri commented Nov 3, 2023

Hi @rezasklggwp, thanks for your feedback. Could you show us a complete, standalone example program or reproducible demo? If you open an existing workbook, please provide the file attachment without confidential info.

@xuri
Copy link
Member

xuri commented Nov 6, 2023

It seems still not have enough info of code and attachments to reproduce this issue, so I'll close this issue, if you have any questions, please let me know to reopen this anytime.

@xuri xuri closed this as completed Nov 6, 2023
@xuri
Copy link
Member

xuri commented Nov 8, 2023

Hi @here-bossnanda, @rezasklggwp, this issue similar with the issue #672, and it has been fixed in the #673 in v2.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info This issue can't reproduce, need more info
Projects
None yet
Development

No branches or pull requests

2 participants