2
Answers

how to create a notepad in windows form c#.net

Nitin Sharma

Nitin Sharma

10y
3.6k
1
Dear All
I have almost crated a notepad for using windows form and c#.net . In this application i have used a richTextBox and menustrip control, all coding i have done but word warp code not work, i have using this code but this code show an error "instance ref not set"
wordWrapToolStripMenuItem.Checked = !(wordWrapToolStripMenuItem.Checked);
richTextBox1.WordWrap = wordWrapToolStripMenuItem.Checked; 
Kindly please help me and advice the code of wordwrap
also advise me the code of find, find next, replace and goto. 
Answers (2)
0
SriHari VP

SriHari VP

NA 163 3.1k 7y
You will need to get reference to the active sheet and set a name to it.
 
Microsoft.Office.Interop.Excel.Workbook workBook;
Microsoft.Office.Interop.Excel.Worksheet workSheet;
 
workBook = XcelApp.Application.Workbooks.Add(Type.Missing);
workSheet = (Microsoft.Office.Interop.Excel.Worksheet) workBook.ActiveSheet;
workSheet.Name = "Sams Report";
0
Leon D

Leon D

NA 479 51 7y
I'd suggest you use a free third party library free Spire.XLS to export data to excel, it's easy and doesn't rely on Excel. You can get free Spire.XLS dll from NuGet Package Manager and refer to the following code:
  1. DataTable dt = dataGridView1.DataSource as DataTable;  
  2. Workbook workbook = new Workbook();  
  3. Worksheet sheet = workbook.Worksheets[0];  
  4. sheet.Name = "Sams Report";  
  5. sheet.InsertDataTable(dt, true, 1, 1);  
  6. workbook.SaveToFile("Report.xlsx", ExcelVersion.Version2013);  
0
Amit Gupta

Amit Gupta

NA 16.5k 25.7k 7y
Then you have to set the title of the excel application, this will gives you the expected filename when saving
0
james james

james james

NA 175 2.9k 7y
I spoke wrong this is what i need to do without having to save the file.
 
The below code when exporting to excel gives the Book name Book1. How can i edit it to export the Book name as "Sams Report"?
0
Amit Gupta

Amit Gupta

NA 16.5k 25.7k 7y
You can write above the for loop
0
james james

james james

NA 175 2.9k 7y
Amit
 
where do I place that in my code or what do I replace?
getting build error.
 
Thanks 
0
Amit Gupta

Amit Gupta

NA 16.5k 25.7k 7y
  1. Microsoft.Office.Interop.Excel.Worksheet worksheet = (Worksheet)xlApp.Worksheets["Sheet1"];  
  2.   worksheet.Name = “NewTabName”