I open the book, work with it, then close it, keep everything well. But such a question, and if I wrote something in it and I need to save only the recorded results in the new excel file !!

As I understand, there are two options. 1) This is through SaveAs. Create a copy of the book, somehow clean it, write, save. 2) Create a new book and write there.

The problem is, I do not know how to create a new book, but if it is too cumbersome. Is there any method that clears all the cells of the book or do you have to write your own?

In the documentation I did not find anything sensible, maybe I did not carefully look at it.

Thank!

  • you can select everything and clean it up - titov_andrei
  • do not tell me how to select? - user209821
  • Work their Excel or third-party programs? How to save? In the same cells? In the same range? Why save only the entered data? Maybe create a registry of changes: when a change is made in a book, the data is added to the registry? But if there are a lot of edits, then the registry will swell up ... The end goal is incomprehensible, and without that, advising something - a finger to the sky ... - vikttur

1 answer 1

A new book:

using ClosedXML.Excel; void toexel() { string FileName; // путь к Excel файлу // Создание новой книги var workbook = new XLWorkbook(FileName); var worksheet = workbook.Worksheets.Add("Новая книга"); // Работа с книгой worksheet.Cell(1, 1).Value = "Запись в ячейке 1 1"; // worksheet.Columns().AdjustToContents(); workbook.Save(); MessageBox.Show("Завершено"); } 

Clear book:

 using ClosedXML.Excel; void clearexel() { string FileName; // путь к Excel файлу var workbook = new XLWorkbook(FileName); workbook.Worksheet("Название книги").Clear(); workbook.Save(); MessageBox.Show("Завершено"); }