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

Does save or save as not support saving shape? #1252

Open
93910676wangd opened this issue Jul 15, 2019 · 4 comments · May be fixed by #1725
Open

Does save or save as not support saving shape? #1252

93910676wangd opened this issue Jul 15, 2019 · 4 comments · May be fixed by #1725

Comments

@93910676wangd
Copy link

93910676wangd commented Jul 15, 2019

Version of ClosedXML

0.94.2

Does save or save as not support saving shape?
There is a shape in my aaa. xlsx file and a text in the shape.
Open the file and save it (save or save as). There are no shapes in the saved file.
Open it with 7zip and find that drawings are not available under xl. Does the current version not support drawings yet?

Code to reproduce problem:

    static void Main(string[] args)
    {
        //Console.WriteLine("Hello World!");

        try
        {
            //using (var workbook = XLWorkbook.OpenFromTemplate(@"D:\aaa.xlsx"))
            using (var workbook = new XLWorkbook(@"D:\aaa.xlsx"))
            {
                //var worksheet = workbook.Worksheets.Add("DA01");

                var worksheet = workbook.Worksheet("aaa");
                worksheet.Cell("A6").Value = "Test";
                workbook.Save();
                //workbook.SaveAs(@"D:\aaa_saveas.xlsx");

            }

            Console.WriteLine("finished");
        }
        catch(Exception ex) {
            Console.WriteLine(ex.Message);
        }

        Console.ReadKey();
    }

aaa.xlsx

@igitur
Copy link
Member

igitur commented Jul 15, 2019

Please attach your input file.

@93910676wangd
Copy link
Author

93910676wangd commented Jul 15, 2019

aaa.xlsx
after saved->red shape is none

@NguyenTam
Copy link

NguyenTam commented Apr 24, 2020

This bug appears in ClosedXML 0.95.1 as well. I have tested @93910676wangd code with slight correction:
workbook.Worksheet("aaa"); => workbook.Worksheet("111");

My conclusion: The red rectangle dissappeared.

Below is @93910676wangd 's code without "using" namespace:
EDIT: code quoting

    class Program
    {
        static void Main(string[] args)
        {

            //Console.WriteLine("Hello World!");
            try
            {
                
                //using (var workbook = XLWorkbook.OpenFromTemplate(@"D:\aaa.xlsx"))
                using (var workbook = new ClosedXML.Excel.XLWorkbook(@"PATH_TO\aaa.xlsx"))
                {
                    //var worksheet = workbook.Worksheets.Add("DA01");

                    var worksheet = workbook.Worksheet("111");
                    worksheet.Cell("A6").Value = "Test";
                    workbook.Save();
                    //workbook.SaveAs(@"D:\aaa_saveas.xlsx");

                }

                System.Console.WriteLine("finished");
            }
            catch (System.Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }

            System.Console.ReadKey();

        }
    }

@adm90
Copy link

adm90 commented Oct 6, 2021

I have confirmed the behavior of the problem that the shape disappears when saving.

  • OK: 0.91.1 or less
  • NG: 0.92.0 or later

I found a workaround.
If you paste the image and save it, the shape will not be deleted.
I made a pull request to fix this issue. It may be possible to fix it in the near future.
PR1725 Fix shape disappear if there was no image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants