Hi,
I am trying to use your code to insert page breaks and ensure it fits correct page width (1 page width). Somehow your code with 50 rows for a page break work, but if you try to use different page size (change 50 to 25) then it doesn't work as expected. Please advise what is the correct way to achive this?
What I am trying to do is write a set of rows (say 45) into a sheet and then insert a horizontal page break. This is not working as expected.
Dim rowCtr, column As Integer
column = 10
For i As Integer = 0 To 499
rowCtr += 1
worksheet(rowCtr, 1).Text = "Page Break applied after every 50 Lines. " + i.ToString()
If rowCtr Mod 25 = 0 Then
worksheet.HPageBreaks.Add(worksheet(rowCtr, column))
End If
Next
worksheet.PageSetup.FitToPagesTall = 5
worksheet.PageSetup.FitToPagesWide = 1
Thanks!
Sunil
Hi Keerthi,
I am using 19.4.0.41
Hi,
I have two more questions.
1) I am importing datatable into Spreadsheet. While doing that, i have some numeric values that I need to insert as is. For example 01234, while importing this trailing zero is gone as excel treating as number. How can i treat as text?
2) Writing data to Excel cell. Need to format the string in different ways. Example below
This is a sentence I need, but few words should be in bold in a cell.
Is there a way I can write a sentence to a single cell?
Thanks!
Sunil
|
Query |
Response | |
|
I am trying to use your code to insert page breaks and ensure it fits correct page width (1 page width). Somehow your code with 50 rows for a page break work, but if you try to use different page size (change 50 to 25) then it doesn't work as expected. Please advise what is the correct way to achive this?
What I am trying to do is write a set of rows (say 45) into a sheet and then insert a horizontal page break. This is not working as expected.
Dim rowCtr, column As Integer
column = 10
For i As Integer = 0 To 499
rowCtr += 1
worksheet(rowCtr, 1).Text = "Page Break applied after every 50 Lines. " + i.ToString()
If rowCtr Mod 25 = 0 Then
worksheet.HPageBreaks.Add(worksheet(rowCtr, column))
End If
Next
worksheet.PageSetup.FitToPagesTall = 5
worksheet.PageSetup.FitToPagesWide = 1
|
FitToPagesTall and FitToPagesWide splits the content in the worksheet to fit in that provided count.
If your main requirement is to set page break at specified row, we suggest you to use the below modified code snippet.
Code Snippet:
| |
|
I am importing datatable into Spreadsheet. While doing that, i have some numeric values that I need to insert as is. For example 01234, while importing this trailing zero is gone as excel treating as number. How can i treat as text? |
The leading zeros can be preserved by assigning text number format to the cell. For this first you need to set the number format and then import data into the cell.
Please look into the following link for more information.
| |
|
Writing data to Excel cell. Need to format the string in different ways. Example below
This is a sentence I need, but few words should be in bold in a cell.
Is there a way I can write a sentence to a single cell?
|
Your requirement can be achieved through Rich-Text concept in Syncfusion XlsIO. Please look into the following link for more information.
|
Hi Keerthi,
All solutions suggested by you works well! Thanks a lot for your help! For pagebreak, at one place of code I was setting the FitToPagesTall to 999, which was overriding the page breaks. Removing that solved the issue. I can still keep below attributes, if that helps someone.
worksheet.PageSetup.FitToPagesTall = 0
worksheet.PageSetup.FitToPagesWide = 1
Thnk