I add a style in doc but if style font Name is Mounted on word It does not work!!!
my font is a PersianFont
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Aspose.Words.Style style = doc.Styles.Add(StyleType.Paragraph, "newStyle");
style.IsQuickStyle = true;
style.Font.Size = 24;
style.Font.Name = "B Mitra";
builder.ParagraphFormat.Style = style;
builder.Writeln("سلام");
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Aspose.Words.Style style = doc.Styles.Add(StyleType.Paragraph, "newStyle");
style.IsQuickStyle = true;
style.Font.Size = 24;
style.Font.SizeBi= 24;
style.Font.Name = "B Mitra";
style.Font.NameBi= "B Mitra";
builder.ParagraphFormat.Style = style;
builder.Writeln("سلام");
Related
I want to apply some styles that are predefined in word. My code is as follows, but the style "Heading1" doesn't work.
WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(document, true);
Body body = wordprocessingDocument.MainDocumentPart.Document.Body;
Paragraph p = new Paragraph();
ParagraphProperties ppr = new ParagraphProperties();
ParagraphStyleId stid = new ParagraphStyleId() { Val = "Heading1" };
ppr.Append(stid);
p.Append(ppr);
In c#, Rich text content are saved to database in below format
< b>Hello< /b>.
I need to export this to MS Excel sheet as Hello (with bold letters)
When ever i try to export the content in excel , its not showing in rich text. Kindly help me . Thanks,
var workbook = new HSSFWorkbook();
var sheet = workbook.CreateSheet("");
int rowNumber = 1;
NPOI.SS.UserModel.IFont font = workbook.CreateFont();
font.Boldweight = (short)(NPOI.SS.UserModel.FontBoldWeight.BOLD);
font.FontHeight = 210;
font.FontName = "Calibri";
NPOI.SS.UserModel.ICellStyle headerCell = workbook.CreateCellStyle();
headerCell.FillBackgroundColor = NPOI.SS.UserModel.IndexedColors.GREY_25_PERCENT.Index;
headerCell.FillForegroundColor = NPOI.SS.UserModel.IndexedColors.GREY_25_PERCENT.Index;
headerCell.FillPattern = NPOI.SS.UserModel.FillPatternType.SOLID_FOREGROUND;
headerCell.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.CENTER;
headerCell.WrapText = true;
headerCell.SetFont(font);
headerCell.BorderBottom = NPOI.SS.UserModel.BorderStyle.THIN;
headerCell.BorderLeft = NPOI.SS.UserModel.BorderStyle.THIN;
headerCell.BorderRight = NPOI.SS.UserModel.BorderStyle.THIN;
headerCell.BorderTop = NPOI.SS.UserModel.BorderStyle.THIN;
NPOI.SS.UserModel.IFont fontShort = workbook.CreateFont();
fontShort.Boldweight = (short)(NPOI.SS.UserModel.FontBoldWeight.NORMAL);
fontShort.FontName = "Calibri";
NPOI.SS.UserModel.ICellStyle normalCell = workbook.CreateCellStyle();
normalCell.FillBackgroundColor = 50;
normalCell.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.CENTER;
normalCell.WrapText = true;
normalCell.SetFont(fontShort);
normalCell.BorderBottom = NPOI.SS.UserModel.BorderStyle.THIN;
normalCell.BorderLeft = NPOI.SS.UserModel.BorderStyle.THIN;
normalCell.BorderRight = NPOI.SS.UserModel.BorderStyle.THIN;
normalCell.BorderTop = NPOI.SS.UserModel.BorderStyle.THIN;
NPOI.SS.UserModel.ICellStyle emptyCell = workbook.CreateCellStyle();
emptyCell.SetFont(font);
emptyCell.BorderBottom = NPOI.SS.UserModel.BorderStyle.NONE;
emptyCell.BorderLeft = NPOI.SS.UserModel.BorderStyle.NONE;
emptyCell.BorderRight = NPOI.SS.UserModel.BorderStyle.NONE;
emptyCell.BorderTop = NPOI.SS.UserModel.BorderStyle.NONE;
var headerRow = sheet.CreateRow(0);
var output ="<b>HelloWorld</b>"
var row = sheet.CreateRow(rowNumber++);
row.CreateCell(0).SetCellValue(output);
row.Cells[0].CellStyle = normalCell;
I am using openXML, Asp.net and c# to create an Excel workbook, I have a requirement that to make Header row of all sheets should be bold.
WorkbookStylesPart stylesPart = workbookpart.AddNewPart<WorkbookStylesPart>();
stylesPart.Stylesheet = CreateStylesheet();
stylesPart.Stylesheet.Save();
}
private static Stylesheet CreateStylesheet()
{
Stylesheet ss = new Stylesheet();
Fonts fts = new Fonts();
DocumentFormat.OpenXml.Spreadsheet.Font ft = new DocumentFormat.OpenXml.Spreadsheet.Font();
Bold fbld = new Bold();
FontName ftn = new FontName();
ftn.Val = "Calibri";
DocumentFormat.OpenXml.Spreadsheet.FontSize ftsz = new DocumentFormat.OpenXml.Spreadsheet.FontSize();
ftsz.Val = 11;
ft.FontName = ftn;
ft.FontSize = ftsz;
ft.Bold = fbld;
fts.Append(ft);
fts.Count = (uint)fts.ChildElements.Count;
ss.Append(fts);
return ss;
}
It is making all the cells bold, I am missing the code that apply this to a particular row/cells
Thanks in Advance,
AR
I got the Answer from another post.
Create Excel file with style tag using OpenXmlWriter SAX
private static Stylesheet CreateStylesheet()
{
Stylesheet ss = new Stylesheet();
Font font0 = new Font(); // Default font
Font font1 = new Font(); // Bold font
Bold bold = new Bold();
font1.Append(bold);
Fonts fonts = new Fonts(); // <APENDING Fonts>
fonts.Append(font0);
fonts.Append(font1);
// <Fills>
Fill fill0 = new Fill(); // Default fill
Fills fills = new Fills(); // <APENDING Fills>
fills.Append(fill0);
// <Borders>
Border border0 = new Border(); // Defualt border
Borders borders = new Borders(); // <APENDING Borders>
borders.Append(border0);
CellFormat cellformat0 = new CellFormat() { FontId = 0, FillId = 0, BorderId = 0 }; // Default style : Mandatory | Style ID =0
CellFormat cellformat1 = new CellFormat(){FontId = 1};
CellFormats cellformats = new CellFormats();
cellformats.Append(cellformat0);
cellformats.Append(cellformat1);
ss.Append(fonts);
ss.Append(fills);
ss.Append(borders);
ss.Append(cellformats);
return ss;
}
I've seen this question: Creating PowerPoint presentations programmatically, but that question asks "Can you?" to which the answer is "yes".
But I'm asking "How?" and specifically "From a list of images?"
Here's what I do to break a ppt up into images
var app = new PowerPoint.Application();
var pres = app.Presentations;
var file = pres.Open(input, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
file.SaveAs(output, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsJPG, MsoTriState.msoTrue);
file.Close();
app.Quit();
How do I do the reverse?
It'll be something like this:
string pictureFileName = "C:\\temp\\test.jpg";
Application pptApplication = new Application();
Microsoft.Office.Interop.PowerPoint.Slides slides;
Microsoft.Office.Interop.PowerPoint._Slide slide;
Microsoft.Office.Interop.PowerPoint.TextRange objText;
// Create the Presentation File
Presentation pptPresentation = pptApplication.Presentations.Add(MsoTriState.msoTrue);
Microsoft.Office.Interop.PowerPoint.CustomLayout customLayout = pptPresentation.SlideMaster.CustomLayouts[Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText];
// Create new Slide
slides = pptPresentation.Slides;
slide = slides.AddSlide(1, customLayout);
// Add title
objText = slide.Shapes[1].TextFrame.TextRange;
objText.Text = "test";
objText.Font.Name = "Arial";
objText.Font.Size = 32;
objText = slide.Shapes[2].TextFrame.TextRange;
objText.Text = "Content goes here\nYou can add text\nItem 3";
Microsoft.Office.Interop.PowerPoint.Shape shape = slide.Shapes[2];
slide.Shapes.AddPicture(pictureFileName,Microsoft.Office.Core.MsoTriState.msoFalse,Microsoft.Office.Core.MsoTriState.msoTrue,shape.Left, shape.Top, shape.Width, shape.Height);
slide.NotesPage.Shapes[2].TextFrame.TextRange.Text = "Test";
pptPresentation.SaveAs(#"c:\temp\test.pptx", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoTrue);
//pptPresentation.Close();
//pptApplication.Quit();
I want to make table using OpenXML WordProcessing. I want to format the font inside the cell. This is my code
MainDocumentPart mainDocumentPart = doc.AddMainDocumentPart();
mainDocumentPart.Document = new Document();
Body body = mainDocumentPart.Document.AppendChild(new Body());
RunProperties runHeader = new RunProperties();
RunFonts runFont = new RunFonts();
runFont.Ascii = "Lucida Sans";
runHeader.Append(runFont);
runHeader.Append(new Bold());
runHeader.Append(new FontSize() { Val = "16" });
//// Create a new table
Table tbl = new Table();
tr = new TableRow();
tc = new TableCell();
Paragraph paraHeader = new Paragraph();
Text heading_text = new Text("Company Name");
runHeader.Append(heading_text);
paraHeader.Append(runHeader);
tc.Append(paraHeader);
tr.Append(tc);
tbl.Append(tr);
body.AppendChild(tbl);
But when I open up on Microsoft Word, I got error. Its said that the file has problem with the contents
You are appending your text to your Run Properties, it needs to be appended to a Run.
try:
Text heading_text = new Text("Company Name");
////create the run
Run runHeaderRun = new Run();
////append the run properties and text to the run
runHeaderRun.Append(runHeader);
runHeaderRun.Append(heading_text);
////append the run to the paragraph
paraHeader.Append(runHeaderRun);
tc.Append(paraHeader);
RunProperties rp = new RunProperties();
RunFonts runFont = new RunFonts() { Ascii = "Calibri Light" };
rp.Append(runFont);
rp.Append(new Color() { Val = "#2E74B5" });
body.Append(new DocumentFormat.OpenXml.Wordprocessing.Paragraph(new Run(rp, new Text("3. Risk Assessment"))));
It's a really simple to use, try this.