نوشته شده توسط
Mahmoud.Afrad
کد همون قسمت رو بزارید.
چک کنید ببینید میشه جدول رو راست به چپ کرد یا نه.
متاسفانه ورد راست چین نشد کد اون قسمتم میزارم براتون
static public void ToWord(DataTable mytable,List<string> myHeader)
{
Document doc = new Document();
Section s = doc.AddSection();
s.TextDirection = TextDirection.RightToLeftRotated;
Table table = s.AddTable(true);
//Add Cells
table.ResetCells(mytable.Rows.Count + 1, myHeader.Count);
//Header Row
TableRow FRow = table.Rows[0];
FRow.IsHeader = true;
//Row Height
FRow.Height = 23;
//Header Format
FRow.RowFormat.BackColor = Color.AliceBlue;
for (int i = 0; i < myHeader.Count;i++ )
{
//Cell Alignment
Paragraph p = FRow.Cells[i].AddParagraph();
FRow.Cells[i].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
p.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
//Data Format
TextRange TR = p.AppendText(myHeader[i]);
TR.CharacterFormat.FontName = "B Nazanin";
TR.CharacterFormat.FontSize = 14;
TR.CharacterFormat.TextColor = Color.Teal;
TR.CharacterFormat.Bold = true;
}
//Data Row
for (int r = 0; r < mytable.Rows.Count; r++)
{
TableRow DataRow = table.Rows[r + 1];
//Row Height
DataRow.Height = 20;
//C Represents Column.
for (int c = 0; c < mytable.Columns.Count; C++)
{
//Cell Alignment
DataRow.Cells[c].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
//Fill Data in Rows
Paragraph p2 = DataRow.Cells[c].AddParagraph();
TextRange TR2 = p2.AppendText(mytable.Rows[r][c].ToString());
//Format Cells
p2.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
TR2.CharacterFormat.FontName = "B Nazanin";
TR2.CharacterFormat.FontSize = 12;
TR2.CharacterFormat.TextColor = Color.Brown;
}
}
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Word files (*.docx)|*.docx";
//Empty the FileName text box of the dialog
sfd.FileName = String.Empty;
//Set default extension as .txt
sfd.DefaultExt = ".docx";
//Open the dialog and determine which button was pressed
DialogResult result = sfd.ShowDialog();
//If the user presses the Save button
if (result == DialogResult.OK)
{
doc.SaveToFile(sfd.FileName, FileFormat.Docx2013);
DialogResult dr = MessageBox.Show("آیا میخواهید فایل باز شود؟","",MessageBoxButtons.YesNo);
if (dr == DialogResult.Yes)
{
System.Diagnostics.Process.Start(sfd.FileName);
}
}
}
از spireاستفاده میکنم این کد رو طبق مستنداتش میزارم اما راست چین نیست
s.TextDirection = TextDirection.RightToLeftRotated;