在我的应用程序中的某处,我需要创建幻灯片幻灯片并使用数据库值填充它。我可以使用本地模板创建幻灯片。但我不知道如何用DB值填充它。我搜索了网页,发现this,但它没有帮助我。没有图表或图表我想填充。这只是基于DB值的简单文本。
有人可以帮我吗?使用数据库值填充幻灯片演示文稿
1
A
回答
5
下面的代码允许您创建一个新的幻灯片,选择它并将值添加到表中。你只需要现在阅读DB和填写好
int newaddslidecounter = 0; // checking how many new slides have to be inserted in order to split the table
int startmultiplicator=1; // used in order to return current table row that must be pasted in new table
int amountrowsshown =7; // amount of shown rows per table
int fontsize = 12;
// set position of new table/chart
int topsize = 100;
int leftsize = 100;
int widthsize = 150;
int heightsize = 150;
Boolean alreadycreated = false; // checks if a table has already been created
//Resizing all tables
//and insert new Excel table instead while importing data from Excel table
//used for visualization of data
foreach (PowerPoint.Slide slide in presentation.Slides)
{
slide.Select();
//loop through all shapes in slide
foreach (PowerPoint.Shape pptshape in slide.Shapes)
{
//Console.WriteLine("Shape type : " + pptshape.Type.ToString());
//check if current shape is a table
//in order to do the manipulation
if (pptshape.Type.ToString().Equals("msoTable"))
{
for (int i = 1; i <= pptshape.Table.Rows.Count; i++)
{
for (int j = 1; j <= pptshape.Table.Columns.Count; j++)
{
/// checks if the module of the current row and the amount of maximum
/// shown rows to be visible in table is the same
// Console.WriteLine("row= " + i + " col= " + j);
if ((i % amountrowsshown) == 0 && alreadycreated == false)
{
PowerPoint.Table objTable = null;
/// Add new slide if table requires more than one slide
if (newaddslidecounter == 0)
{
/// Add new table object in the slide
objTable = presentation.Slides[slide.SlideIndex].Shapes.AddTable(amountrowsshown, pptshape.Table.Columns.Count, topsize, leftsize, slide.Master.Width - widthsize, slide.Master.Height - heightsize).Table;
}
else
{
presentation.Slides.Add(slide.SlideIndex + newaddslidecounter, NetOffice.PowerPointApi.Enums.PpSlideLayout.ppLayoutClipArtAndVerticalText);
/// Add new table object in the slide
objTable = presentation.Slides[slide.SlideIndex + newaddslidecounter].Shapes.AddTable(amountrowsshown, pptshape.Table.Columns.Count, topsize, leftsize, slide.Master.Width - widthsize, slide.Master.Height - heightsize).Table;
}
int incrementer = 1;
/// Run through the created new table and paste all the previous table values
for(int k=startmultiplicator;k<=i;k++)
{
for(int l=1;l<=pptshape.Table.Columns.Count;l++)
{
objTable.Cell(incrementer,l).Shape.TextFrame.TextRange.Text=pptshape.Table.Cell(k,l).Shape.TextFrame.TextRange.Text;
objTable.Cell(incrementer, l).Shape.TextFrame.TextRange.Font.Size = fontsize;
}
incrementer++;
}
startmultiplicator += amountrowsshown;
alreadycreated = true;
newaddslidecounter++;
}
}
alreadycreated = false;
}
/// In case is still some rows left which haven't been considered
/// we copy those in a new table
//Console.WriteLine("Create new table before leaving");
// Console.WriteLine(startmultiplicator);
if (startmultiplicator <= pptshape.Table.Rows.Count)
{
PowerPoint.Table objTable = null;
if (startmultiplicator < amountrowsshown)
{
/// Add new table object in the slide
objTable = presentation.Slides[slide.SlideIndex].Shapes.AddTable(amountrowsshown, pptshape.Table.Columns.Count, topsize, leftsize, slide.Master.Width - widthsize, slide.Master.Height - heightsize).Table;
}
else
{
/// Don't add new slide for last rows
presentation.Slides.Add(slide.SlideIndex + newaddslidecounter, NetOffice.PowerPointApi.Enums.PpSlideLayout.ppLayoutClipArtAndVerticalText);
// Add new table object in the slide
objTable = presentation.Slides[slide.SlideIndex + newaddslidecounter].Shapes.AddTable(amountrowsshown, pptshape.Table.Columns.Count, topsize, leftsize, slide.Master.Width - widthsize, slide.Master.Height - heightsize).Table;
}
int incrementer = 1;
/// Run through the created new table and paste all the previous table values
for (int k = startmultiplicator; k <= pptshape.Table.Rows.Count; k++)
{
for (int l = 1; l <= pptshape.Table.Columns.Count; l++)
{
objTable.Cell(incrementer, l).Shape.TextFrame.TextRange.Text = pptshape.Table.Cell(k, l).Shape.TextFrame.TextRange.Text;
objTable.Cell(incrementer, l).Shape.TextFrame.TextRange.Font.Size = fontsize;
}
incrementer++;
}
objTable.Application.Top = topsize;
objTable.Application.Left = leftsize;
objTable.Application.Width = slide.Master.Width - widthsize;
objTable.Application.Height = slide.Master.Height - heightsize;
}
pptshape.Delete();
}
}
newaddslidecounter=0;
startmultiplicator=1;
}
**编辑:
代码源从数据库中读取数据 Reading values from SQL database in C#
using (SqlConnection connection = new SqlConnection(connectionString)
using (SqlCommand command = new SqlCommand("select * from Requests where Complete = 0", connection))
{
connection.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine(reader["Username"].ToString());
Console.WriteLine(reader["Item"].ToString());
Console.WriteLine(reader["Amount"].ToString());
Console.WriteLine(reader["Complete"].ToString());
}
}
}
联接到一个数据库,例如可以在这里找到:
try
{
SqlConnection thisConnection = new SqlConnection(@"Network Library=DBMSSOCN;Data Source=192.168.0.100,1433;database=Northwind;User id=Paladine;Password=;");
thisConnection.Open();
SqlCommand thisCommand = thisConnection.CreateCommand();
thisCommand.CommandText = "SELECT CustomerID, CompanyName FROM Customers";
SqlDataReader thisReader = thisCommand.ExecuteReader();
while (thisReader.Read())
{
Console.WriteLine("\t{0}\t{1}", thisReader["CustomerID"], thisReader["CompanyName"]);
}
thisReader.Close();
thisConnection.Close();
}
catch (SqlException e)
{
Console.WriteLine(e.Message);
}
相关问题
- 1. 绘制R演示文稿中没有填充幻灯片
- 2. 如何使用ioslides在rmarkdown演示文稿中填充整个幻灯片?
- 3. 使用VBA和Excel生成幻灯片演示文稿
- 4. 使用Rails创建幻灯片演示文稿
- 5. 将代码示例添加到幻灯片演示文稿
- 6. 将OpenOffice幻灯片从一个演示文稿复制到另一个演示文稿中使用
- 7. PHP:使用opendir填充JS幻灯片
- 8. 使用servlet进行幻灯片演示
- 9. 通过win32ole在ruby中打开幻灯片演示文稿
- 10. 在PowerPoint演示文稿中复制幻灯片
- 11. 在pdf格式上下载谷歌幻灯片演示文稿
- 12. 如何在R演示文稿幻灯片中放置图像?
- 13. 将一张幻灯片复制到多个演示文稿
- 14. 在C#中的PowerPoint演示文稿中添加幻灯片
- 15. 将PowerPoint幻灯片插入正在运行的演示文稿
- 16. 如何分享Google幻灯片演示文稿API?
- 17. 编辑R Markdown Slidy演示文稿的标题幻灯片
- 18. 如何通过python打开幻灯片演示文稿?
- 19. 如何将幻灯片编号添加到PowerPoint演示文稿
- 20. 使用Applescript在演示文稿中运行指定幻灯片的幻灯片放映
- 21. 如何使用串行通信更改幻灯片的PowerPoint演示文稿?
- 22. 用Python语法突出显示的HTML演示文稿幻灯片
- 23. 以编程方式将来自多个演示文稿的幻灯片合并为一个演示文稿
- 24. 在幻灯片放映模式下打开幻灯片演示
- 25. VBA根据特定词选择幻灯片并复制到新演示文稿
- 26. jQuery Cycle Plugin - 当使用div作为幻灯片时,幻灯片填充消失
- 27. 不要在闪亮/ rmarkdown演示文稿中显示幻灯片编号?
- 28. html5/js:幻灯片上的填充环
- 29. Flash幻灯片演示全屏
- 30. ajQuery - 点击开始幻灯片演示
你给的链接可以帮助你创建一个表,你在找什么?您只需返回数据库值和每行,在Powerpoint中创建一个新表并填充它。 – mike27015