@amjad.sahi, @Professionalize.Discourse, @John.He, @simon.zhao
worksheet.PageSetup.PaperSize = PaperSizeType.Custom;
// Set custom paper size for A1 (width: 33.1 inches, height: 23.4 inches)
worksheet.PageSetup.CustomPaperSize((150)) / 96), ((1500) / 96));
// Orientation
worksheet.PageSetup.Orientation = PageOrientationType.Landscape;
this (150px)) / 96) and (1500px)) / 96) will use daynemic how to possible
@imparthgalani
For how to implement custom paper size of Worksheet for rendering, please refer to the following document.
int firstRow = 0;
int lastRow = worksheet.Cells.MaxDisplayRange.RowCount - 1;
int firstCol = 0;
int lastCol = worksheet.Cells.MaxDisplayRange.ColumnCount - 1;
double totalHeightPx = 0;
for (int i = firstRow; i <= lastRow; i++)
totalHeightPx += worksheet.Cells.GetRowHeightPixel(i);
double totalWidthPx = 0;
for (int j = firstCol; j <= lastCol; j++)
totalWidthPx += worksheet.Cells.GetColumnWidthPixel(j);
double heightInInches = totalHeightPx / 96.0;
double widthInInches = totalWidthPx / 96.0;
worksheet.PageSetup.PaperSize = PaperSizeType.Custom;
worksheet.PageSetup.CustomPaperSize(heightInInches, widthInInches);
worksheet.PageSetup.Orientation = PageOrientationType.Landscape;
this will proper not working widthInInches last 15 colun cut issue
@imparthgalani,
We’re unsure about the specifics of your issue. Could you kindly provide additional details along with a standalone, runnable code sample or a sample console application and the relevant Excel file(s)? This will help us investigate your concern promptly.
P.S. Please ensure the files are zipped before attaching them here.
新規工事件名シート(1)_250702~260830 (23).zip (502.5 KB)
How can I convert the entire Excel file into a single-page SVG without cutting off any content?
Sample in zip (新規工事件名シート(1)_250702~260830 (23).zip) Excel SVG create time cut off issue.
using Aspose.Cells;
public class SetColumnWidthExample
{
public static void Run()
{
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
int firstRow = 0;
int lastRow = worksheet.Cells.MaxDisplayRange.RowCount - 1;
int firstCol = 0;
int lastCol = worksheet.Cells.MaxDisplayRange.ColumnCount - 1;
double totalHeightPx = 0;
for (int i = firstRow; i <= lastRow; i++)
totalHeightPx += worksheet.Cells.GetRowHeightPixel(i);
double totalWidthPx = 0;
for (int j = firstCol; j <= lastCol; j++)
totalWidthPx += worksheet.Cells.GetColumnWidthPixel(j);
double heightInInches = totalHeightPx / 96.0;
double widthInInches = totalWidthPx / 96.0;
worksheet.PageSetup.PaperSize = PaperSizeType.Custom;
worksheet.PageSetup.CustomPaperSize(widthInInches, heightInInches);
worksheet.PageSetup.Orientation = PageOrientationType.Portrait;
// Save the workbook
workbook.Save(newFilePath, SaveFormat.Svg);
}
}
//Download Excle File
[HttpGet]
public ActionResult Download(string fileName)
{
//Get the temp folder and file path in server
string fullPath = Path.Combine(Server.MapPath("~/App_Data"), fileName);
byte[] fileByteArray = System.IO.File.ReadAllBytes(fullPath);
bool fileExists = System.IO.File.Exists(fullPath);
if (fileExists)
{
System.IO.File.Delete(fullPath);
}
return File(fileByteArray, "application/svg+xml", (fileName.Substring(0, fileName.LastIndexOf('_')) + ".svg"));
}
Sorry for the full logic shape not being provided for security reasons i try to set all content is on one page using (MaxDisplayRange.ColumnCount, MaxDisplayRange.RowCount) this will not work .
Also how to set all content is on one page give example.
@imparthgalani,
Please refer to the following sample code that I tried/tested using your template Excel file and it works fine. It gives me SVG file with all the contents on single page and no content/data is clipped.
Workbook workbook = new Workbook("e:\\test2\\ÉVïKìHÄûîÅû+âVü[âg(1)_250702ü`260830.xlsx");
Worksheet worksheet = workbook.Worksheets["Sheet1"];
var imageOptions = new ImageOrPrintOptions
{
OnePagePerSheet = true,
ImageType = ImageType.Svg,
};
var sheetRender = new SheetRender(worksheet, imageOptions);
sheetRender.ToImage(0, "e:\\test2\\out_net1.svg");
Please find attached the output SVG file for your reference.
out_net1.zip (424.9 KB)
Hope, this helps a bit.
var imageOptions = new ImageOrPrintOptions
{
OnePagePerSheet = true,
ImageType = ImageType.Svg,
};
var sheetRender = new SheetRender(worksheet, imageOptions);
Without using the above code, how possible to get all content width and height after setting it as CustomPaperSize? This will take less time
worksheet.PageSetup.CustomPaperSize(widthInInches, heightInInches);
@imparthgalani,
I doubt that it’s feasible or possible to fit such large content onto a single page by just adjusting the paper size. MS Excel might struggle with this and might not do that, but you can attempt to set a custom page in Excel (manually) to see if you can fit everything on one page. If you succeed with Excel (manually), Aspose.Cells should be capable of doing the same.
@imparthgalani ,
It comes to the same requirement. Please refer to your other thread for replies and follow-ups.
@peyton.xu , @amjad.sahi , Thanks for the Quick response…
@imparthgalani ,
You’re welcome. If have have any further requirements, feel free to contact with us.